2012-03-06 26 views
0

我是新来的sencha。我正在开发一个使用treestore和nestedList的应用程序。 我无法加载从coldfusion组件返回的数据。它显示为空。Sencha 2 - 在嵌套列表中显示空值

这里是我的Viewport.js:

Ext.define('Myapp.view.Viewport', { 
    extend: 'Ext.tab.Panel', 
    xtype:'newviewport', 
    config: { 
     fullscreen: true, 
     tabBarPosition: 'top', 
     html: 'hiiiiiiiiiii',  
     cls:'test', 
     items: [ 
       { 
        title: 'Sections', 
        iconCls: 'home',   
        xtype: 'sectionslist' 
       } 
      ] 
       } 
    }); 

我的店:samplestore.js

Ext.define('Myapp.store.samplestore', { 
extend: 'Ext.data.TreeStore', 
config: { 
    autoLoad: true, 
    model: 'Myapp.model.sampleModel', 
    proxy: { 
     type: 'ajax', 
     url: '/sample/sample1.cfc?method=getSections',  
     reader: { 
      type: 'json', 
      rootProperty:'DATA' 
     } 
    } 
} 

});

我的模型:sampleModel.js

Ext.define("Myapp.model.sampleModel", { 
    extend: "Ext.data.Model", 
    config: { 
     fields: [ 
      {name: 'LoginID', type: 'string'}, 
      {name: 'FIRSTNAME', type: 'string'} 
     ] 
    } 
}); 

我sample1.cfc:

<cfcomponent name="sample" output="false"> 
     <cffunction name="getSections" output="no" returnformat="json" access="remote">   
    <cfquery name="qryGetDetails" datasource="#request.dsn#"> 
     SELECT TOP 5 
      LoginID, FIRSTNAME 
     FROM 
      tblUser 
    </cfquery> 
     <cfreturn qryGetDetails> 

    </cffunction> 
</cfcomponent> 

我Sectionslist.js

Ext.define('Myapp.view.Sectionslist', { 
    extend: 'Ext.dataview.NestedList', 
    xtype: 'sectionslist', 
    config: { 
     store: 'samplestore' 
     itemTpl: [ 
        '{FIRSTNAME}<br/>' 
       ].join(''),  
     onItemDisclosure: function(record, btn, index) { 
       console.log("worked"); 
     } 
     }, 
    //getItemTextTpl: function(node) { 
      //console.log(node); 
     // return node.data.FIRSTNAME+ ':<strong></strong>'; 
    // } 
}); 

最后我的JSON数据:

{"COLUMNS":["LOGINID","FIRSTNAME"],"DATA":[["bt","Jn"],["jr","Jy"],["b20","Best"],["jman","Jeff"],["fenad","Fn"]]} 

请帮忙找出我的问题,我不能引起我哪里错了,我得到空值,因为显示的数据是错误的: itemTpl:[ “{FIRSTNAME}
” ]。加入(“” ),

而不是名字,我应该在这里显示?我试过很多方法,但没有用,请帮忙.....

回答

0

你的JSON正在返回数组的集合像

["bhpAgent", "Jan"], 

但字段定义所期望的响应是象对象的集合

{"LoginID": "bhpAgent", "FIRSTNAME": "Jan"}. 

不确定最佳的解决方案。 ColdFusion可以生成JSON对象吗?

如果不是,可能是子类Ext.data.reader.JSON并覆盖getResponseData()。

也许值得检查TreeStore文档,因为该视图对树结构化数据有更多要求。

+0

感谢您的回复。我将coldfusion结果转换为query结构形式,然后得到结果为{“LoginID”:“bhpAgent”,“FIRSTNAME”:“Jan”}。 – usershaf 2012-03-08 12:21:49

+0

那有用吗? – grumplet 2012-03-08 15:19:03

+0

是的,它的工作:) – usershaf 2012-03-09 10:51:07