问题描述
- extjs 树的问题,加载不出来,后台是用Java到数据读取的数据转换成json格式
-
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="common/common.jsp"%><%
pagemenustr += "addBtn(tb,'" + I18n.getText("erase") + "','C','erase',function(){onClear()});";
pagemenustr += "addBtn(tb,'" + I18n.getText("return") + "','R','arrow_redo',function(){onReturn()});";
pagemenustr += "addBtn(tb,'" + I18n.getText("ok") + "','R','accept',function(){onSubmit()});";%>
<%@include file="common/head.jsp"%>
<br>
var ids='';<br>
var names='';<br>
Ext.override(Ext.tree.TreeLoader, {<br>
createNode : function(attr) {<br>
// apply baseAttrs, nice idea Corey!<br>
if (this.baseAttrs) {<br>
Ext.applyIf(attr, this.baseAttrs);<br>
}<br>
if (this.applyLoader !== alse) {<br>
attr.loader = this;<br>
}<br>
if (typeof attr.uiProvider == 'string') {<br>
attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);<br>
}</p><pre><code> var n = (attr.leaf ?
new Ext.tree.AsyncTreeNode(attr) :
new Ext.tree.AsyncTreeNode(attr));if (attr.expanded) {
n.expanded = true;
}return n;
}
});Ext.onReady(function () {
<%if(!pagemenustr.equals("")){%>
var tb = new Ext.Toolbar();
tb.render('pagemenubar');
<%=pagemenustr%>
<%}%>var orgTree = new Ext.tree.TreePanel({
animate:true,
useArrows :true,
containerScroll: true,
autoScroll:true,
region:'center',
checkModel: 'cascade',
onlyLeafCheckable: false,//对树所有结点都可选
collapsible: true,
collapsed : false,
rootVisible:false,
root:new Ext.tree.AsyncTreeNode({
text: 'text',
id:'root',
expanded:true,
allowDrag:false,
allowDrop:false
}),
loader:new Ext.tree.TreeLoader({dataUrl: "${ctx}/ext/com.cinsea.ext.browser.TreeDirectoryAction",
baseAttrs: { uiProvider: Ext.ux.TreeCheckNodeUI },
preloadChildren:false,
listeners:{"beforeload":function(treeLoader, node) {
treeLoader.baseParams.dimension = '1';
}}
}
),
listeners:{
'expand':function(p){ p.getRootNode().expand();
}
}});
orgTree.on("check",function(node,checked){
if(checked){
if(ids!=''){
ids+=','+node.id;
names+=','+node.text;
}else{
ids+=node.id;
names+=node.text;
}
}else{
if(ids.indexOf(",")==-1){
ids=ids.replace(node.id,'');
names=names.replace(node.text,'');
}else{
ids=ids.replace(","+node.id,'');
names=names.replace(","+node.text,'');
}}
});//Viewport
var viewport = new Ext.Viewport({
layout: 'border',
items: [
{region: 'north', autoScroll: false, split: false, contentEl: 'divSearch'},
orgTree
]
});
})
</script>
</code></pre><p></head><br>
<body></p><div id="divSearch">
<div id="pagemenubar"></div>
</div><script>
function onSubmit(){
alert(ids);
alert(names)
getArray(ids,names);}
function onClear(){
getArray( "0","");
}function onReturn(){
var dg=window.parent?window.parent.xdialog:null;
if (dg) {
dg.hide();
}
window.close();
}
解决方案
直接用浏览器访问你的那个url地址看返回的数据结构对不对,不对就是你java配置问题,返回的数据不正确
解决方案二:
看返回的字段是否和tree需要的字段对应上了
解决方案三:
先通过URL获得返回的json字符串看格式是否正确,如果正确,该是json解析的问题了,看看extjs相关库和路径是否正确