2012-04-26 37 views
0

我想加載一個嵌套列表到我的Sencha應用程序。問題是我不熟悉它,我不知道我使用的json文件是否正確。嵌套列表不加載sencha

[ 
    { 
     "text":[ 


      { 
       "text":"1.1.1", 
       "leaf":true 

      }], 
     "text":[ 

      { 
       "text":"1.1.1", 
       "leaf":true 

      } 
     ] 


    } 
] 

這是我的商店代碼

//Defining the store for the Nested List 
Ext.define('InfoImage.store.nestedListStore', { 
    extend: 'Ext.data.TreeStore', 
    requires: 'InfoImage.model.nestedListModel', 
    id:'nestedListStore', 
    config:{ 

     //Calling the required model for the Work Item List 
     model : 'InfoImage.model.nestedListModel', 
     //Defining the proxy for the Work Item List to pull the data for the List 
     proxy : { 
      type : 'ajax', 
      url : 'app/model/data/list.json', 
      reader: { 
       type: 'json', 
       root: 'items' 

      } 
     }, 
     autoLoad: true 


    } 
}); 

和我的主要代碼

Ext.define("InfoImage.view.nestedList", { 
    extend:'Ext.NestedList', 
    xtype:'nestedList', 
    id:'nestedList', 

    config:{ 
     fullscreen:'true', 
     title:'Nested List', 
     xtype:'nestedList', 
     //displayField : 'text', 
     html:'Nested List on its way!!!', 
     store:'nestedListStore' 
     //itemTpl:'{text}' 
    } 
}); 

顯示的輸出這就是爲[對象的對象。我不知道缺少什麼。任何幫助表示讚賞。

回答

0

看來,因爲text是模型的一個領域,它不應該在你的JSON文件中聲明爲rootProperty你的JSON不能Ext.NestedList工作。

首先,假設你有這樣的模型定義:

Ext.define('ListItem', { 
    extend: 'Ext.data.Model', 
    config: { 
     fields: ['text'] 
    } 
}); 

根據你的數據,你的JSON文件應該是這樣的:

items: [ 
{ 
    text: '1.1', 
    items: [ 
    { text: '1.1.1', leaf: true }, 
    { text: '1.1.2', leaf: true } 
    ] 
    } 
] 

你有這個配置添加到您的店鋪以及defaultRootProperty: 'items'

1

首先,你的Json是一個VALID json。總是被粘貼JSON上jsonlint.com

其次檢查是否有有效的JSON,我看到你註釋掉

displayField:'text' 

財產。如果您不提供displayFieldnestedlist,它不會知道數據存儲中的哪些項目要顯示在列表中。

也許,這就是爲什麼你在列表中獲得[object Object]作爲你的o/p。

取消註釋上述行並檢查。

+0

我試過使用它,但它力度的工作。所以我評論說,如果這是正確的代碼。我無視它並再次嘗試。仍然沒有工作。 – Khush 2012-04-27 03:32:23

+0

它會給你同樣的錯誤嗎?你能不能也發佈你的模型代碼? – 2012-04-27 04:23:12