2012-04-12 134 views
0

我正在使用Sencha V2。我想用Users.json文件中的值填充我的列表。未加载商店

我的列表文件中的代码是

Ext.define('iPolis.view.personlist',{ 
    extend:'Ext.List', 
    xtype: 'personlist', 
    requires: [ 
     'Ext.List', 
     'Ext.form.FieldSet', 
     'Ext.Button' 

    ], 

    config: { 
       fullscreen:true, 
       items: [ 
         { 
         xtype:'toolbar', 
         docked:'top', 
         title:'iPolis', 
          items:[ 
             { 
              ui:'back', 
              icon:'home', 
              iconCls:'home', 
              iconMask:true, 
              id: 'homebtn', 
              handler:function() 
                { 
                } 
             }, 

          ] 
         }, 

         { 
        xtype : 'list', 
        store : 'personListStore', 
        itemTpl : '<div class="contact">HI <br/> {name}</div>' 

         } 
        } 
       ] 

    } 
}); 

和商店调用使用文件:

Ext.define('iPolis.store.personListStore', { 
      extend: 'Ext.data.Store', 
storeId:'personListStore', 
      model : 'iPolis.model.personListModel', 

      proxy : { 
       type : 'ajax', 
       url : '/users.json', 
       reader: { 
        type: 'json', 
        rootProperty: 'users' 
       } 
      }, 
      autoLoad: true 
    }); 

我的JSON文件的代码是:

{ 
    "users": [ 
     { 
      "id": 1, 
      "name": "Ed Spencer", 
      "email": "[email protected]" 
     }, 
     { 
      "id": 2, 
      "name": "Abe Elias", 
      "email": "[email protected]" 
     } 
    ] 
} 

我我刚开了一个黑屏。我已经尝试了一切,但没有数据显示在屏幕上。

+0

首先,'console.log(yourStore.getRange())'确保您的商店实际上从json文件获取数据。其次,请在这里粘贴你的json文件,模型文件的代码,我会帮你调试。 – 2012-04-13 04:23:54

+0

@Thiem:我编辑了代码并添加了json文件。 json数据未被加载到我的列表中。任何做错的事情? – Khush 2012-04-16 08:03:39

回答

0
Ext.define('iPolis.store.personListStore', { 
    extend: 'Ext.data.Store', 
    config:{ 
    model : 'iPolis.model.personListModel', 
    storeId:'personListStore', 
    proxy : { 
     type : 'ajax', 
     url : '/users.json', 
     reader: { 
      type: 'json', 
      rootProperty: 'users' 
     } 
    }, 
    autoLoad: true } }); 

试试这可能对你有帮助。

+0

nope。辛苦工作。我试图使用虚拟数据来填充我的列表,但即使是这样的工作。所以我猜测我的逻辑与列表和商店存在问题。 – Khush 2012-04-16 04:14:31

+0

在商店中添加storeId,并将其作为商店列入商店,并为它提供一些时间。 – 2012-04-16 06:04:56

+0

非常感谢。但是,对于代码 - >“itemTpl:'

HI {name}{
'”,我得到了一行“HI”的响应,没有取自json文件的名称。它给了我一个错误:“XMLHttpRequest无法加载文件:/// D:/TFS/iPolis/app/model/data/users.json?_dc = 1334561794830&page = 1&start = 0&limit = 25。控制允许起源“。 – Khush 2012-04-16 07:39:07

1

在您的列表中,商店是personStore,但您尝试使用personListStore

+0

我在任何地方都使用过personListStore。 M抱歉混淆。我尝试创建商店类的对象并改为使用它。 personListStore不起作用。 – Khush 2012-04-13 02:44:15