2 u014640173 u014640173 于 2014.12.08 11:12 提问

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=&#39;&#39;;<br> var names=&#39;&#39;;<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 == &#39;string&#39;) {<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 () { &lt;%if(!pagemenustr.equals(&quot;&quot;)){%&gt; var tb = new Ext.Toolbar(); tb.render(&#39;pagemenubar&#39;); &lt;%=pagemenustr%&gt; &lt;%}%&gt; var orgTree = new Ext.tree.TreePanel({ animate:true, useArrows :true, containerScroll: true, autoScroll:true, region:&#39;center&#39;, checkModel: &#39;cascade&#39;, onlyLeafCheckable: false,//对树所有结点都可选 collapsible: true, collapsed : false, rootVisible:false, root:new Ext.tree.AsyncTreeNode({ text: &#39;text&#39;, id:&#39;root&#39;, expanded:true, allowDrag:false, allowDrop:false }), loader:new Ext.tree.TreeLoader({ dataUrl: &quot;${ctx}/ext/com.cinsea.ext.browser.TreeDirectoryAction&quot;, baseAttrs: { uiProvider: Ext.ux.TreeCheckNodeUI }, preloadChildren:false, listeners:{&quot;beforeload&quot;:function(treeLoader, node) { treeLoader.baseParams.dimension = &#39;1&#39;; }} } ), listeners:{ &#39;expand&#39;:function(p){ p.getRootNode().expand(); } } }); orgTree.on(&quot;check&quot;,function(node,checked){ if(checked){ if(ids!=&#39;&#39;){ ids+=&#39;,&#39;+node.id; names+=&#39;,&#39;+node.text; }else{ ids+=node.id; names+=node.text; } }else{ if(ids.indexOf(&quot;,&quot;)==-1){ ids=ids.replace(node.id,&#39;&#39;); names=names.replace(node.text,&#39;&#39;); }else{ ids=ids.replace(&quot;,&quot;+node.id,&#39;&#39;); names=names.replace(&quot;,&quot;+node.text,&#39;&#39;); } } }); //Viewport var viewport = new Ext.Viewport({ layout: &#39;border&#39;, items: [ {region: &#39;north&#39;, autoScroll: false, split: false, contentEl: &#39;divSearch&#39;}, orgTree ] }); }) &lt;/script&gt; </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(); }


3个回答

showbo
showbo   Ds   Rxr 2014.12.08 11:30

直接用浏览器访问你的那个url地址看返回的数据结构对不对,不对就是你java配置问题,返回的数据不正确

bdmh
bdmh   Ds   Rxr 2014.12.08 12:01

看返回的字段是否和tree需要的字段对应上了

haishen_Qi
haishen_Qi   2014.12.08 13:17

先通过URL获得返回的json字符串看格式是否正确,如果正确,该是json解析的问题了,看看extjs相关库和路径是否正确

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!