2013-02-15 81 views
3

我試圖將JSON數據加載到NestedList中。我在/app/store/Exhibits.jsSencha Touch 2:'指定的商店無法找到'

以下存儲文件
Ext.define('VisitTCMIndy.store.Exhibits',{ 
requires: ['VisitTCMIndy.model.Exhibit', 'Ext.data.proxy.JsonP'], 
extend: 'Ext.data.TreeStore', 
config: { 
    model: 'VisitTCMIndy.model.Exhibit', 
    proxy: { 
     type: 'jsonp', 
     url: 'http://www.example.com/explore.php', 
     reader: { 
      type: 'json', 
      rootPropery: 'children' 
     } 
    } 
} 
}); 

然後,我引用它在下面的視圖中/app/view/Explore.js

Ext.define('VisitTCMIndy.view.Explore', { 
extend: 'Ext.Container', 
requires: [ 
    'Ext.data.TreeStore', 
    'Ext.dataview.NestedList', 
    'VisitTCMIndy.store.Exhibits', 
], 
xtype: 'explorecard', 
config: { 
    iconCls: 'compass1', 
    title: 'Explore', 
    layout: 'fit', 
    items: [ 
     { 
      xtype: 'titlebar', 
      docked: 'top', 
      title: 'Explore' 
     }, 
     { 
      xtype: 'nestedlist', 
      fullscreen: true, 
      store: 'VisitTCMIndy.store.Exhibits', 
      detailCard: { 
       html: 'Explore Details' 
      }, 
      listeners: { 
       leafitemtap: function(nestedList, list, index, target, record){ 
        var detailCard = nestedList.getDetailCard(); 
        detailCard.setHtml('Exhibit Title: '+ record.get('title')); 
       } 
      } 
     } 

    ] 
} 
}); 

我得到以下警告,當我去的網頁空列表:

[WARN] [Ext.dataview.NestedList#applyStore]指定的商店無法找到

在我的生活中,我無法弄清楚我做錯了什麼。

回答

5

好的。原來,我不得不在我的app.js文件中聲明我的商店和模型。然後在沒有剩下的類定義的情況下通過它的名稱引用我的商店。所以,我添加了以下內容到我的app.js文件中:

models: ['Exhibit'], 
stores: ['Exhibits'], 

然後,這是我更新的Explore.js視圖文件。

Ext.define('VisitTCMIndy.view.Explore', { 
extend: 'Ext.Container', 
requires: [ 
    'Ext.data.TreeStore', 
    'Ext.dataview.NestedList', 
    'VisitTCMIndy.store.Exhibits', 
], 
xtype: 'explorecard', 
config: { 
    iconCls: 'compass1', 
    title: 'Explore', 
    layout: 'vbox', 
    items: [ 
     { 
      xtype: 'titlebar', 
      docked: 'top', 
      title: 'Explore' 
     }, 
     { 
      xtype: 'nestedlist', 
      store: 'Exhibits', 
      title: 'Museum Levels', 
      displayField: 'title', 
      detailCard: { 
       html: 'Explore Details' 
      }, 
      listeners: { 
       leafitemtap: function(nestedList, list, index, target, record){ 
        var detailCard = nestedList.getDetailCard(); 
        detailCard.setHtml('<div style="text-align:center;margin:.5em;"><img src="'+record.get('image')+'" alt="'+record.get('title')+'" />'+ 
         '<p style="text-align:left;">'+record.get('text')+'</p></div>' 
        ); 
       } 
      }, 
      flex: 1 
     } 

    ] 
} 
}); 

此外,請注意我將佈局從適合更改爲vbox。我必須這樣做,然後給列表一個flex,以便列表實際顯示它正在加載數據。

相關問題