List<AcceptOpc> list = businessService.queryAllOpcByAccountId(1);
StringBuffer strOpc = new StringBuffer();
strOpc.append("[{id:'qx',text: '全选',leaf: true,checked: false},");
for (int i = 0; i < list.size(); i++)
{
AcceptOpc opc = list.get(i);
if ((list.size() - 1) > i)
{
strOpc.append("{id:" + opc.getId() + ",leaf:true,checked:false,text:'" + opc.getText() + "'},");
}
else
{
strOpc.append("{id:" + opc.getId() + ",leaf:true,checked:false,text:'" + opc.getText() + "'}");
}
}
strOpc.append("]");
response.getWriter().print(strOpc);
StringBuffer strOpc = new StringBuffer();
strOpc.append("[{id:'qx',text: '全选',leaf: true,checked: false},");
for (int i = 0; i < list.size(); i++)
{
AcceptOpc opc = list.get(i);
if ((list.size() - 1) > i)
{
strOpc.append("{id:" + opc.getId() + ",leaf:true,checked:false,text:'" + opc.getText() + "'},");
}
else
{
strOpc.append("{id:" + opc.getId() + ",leaf:true,checked:false,text:'" + opc.getText() + "'}");
}
}
strOpc.append("]");
response.getWriter().print(strOpc);
本文介绍了一种使用Java从特定业务服务中查询数据并构建动态选项列表的方法。通过遍历查询结果,构造了一个JSON格式的字符串,该字符串可以用于前端展示为树状结构的选择项。此方法适用于需要动态加载数据的应用场景。
1657

被折叠的 条评论
为什么被折叠?



