我从模型中获取的数据无法看到ListView

时间:2013-08-15 09:11:28

标签: list model sencha-touch store

我的代码是,

  Ext.define('notification_list_model', {
        extend: 'Ext.data.Model',
        fields: [{ name: 'firstName', type: 'string' },
                  { name: 'lastName', type: 'string' }]

    });

    var notification_list_store = new Ext.data.Store({    
        model: notification_list_model,
        data: [
            { firstName: 'Berkan', lastName: 'Kahya' },
            { firstName: 'Ahmet', lastName: 'Mutlu' },
            { firstName: 'Ahmet', lastName: 'Mutlu' },
            { firstName: 'Ahmet', lastName: 'Mutlu' }   
        ],           
    });

    var notification_list = new Ext.List({
        store: notification_list_store,
        itemTpl: '<div>{firstName}</div>',
        flex: 1      
    });

listview查看数据,但firstName文本无法打印

2 个答案:

答案 0 :(得分:0)

不要忘记使用sencha documentation

  1. 模型字段应该在config中。
  2. 在商店模型名称中,我应该是一个字符串
  3. <强>模型

    Ext.define('notification_list_model', {
        extend: 'Ext.data.Model',
        config : {
        fields: [{ name: 'firstName', type: 'string' },
                  { name: 'lastName', type: 'string' }]
        }
    });
    

    商品

    var notification_list_store = new Ext.data.Store({
        model:'notification_list_model',
        data: [
            { firstName: 'Berkan', lastName: 'Kahya' },
            { firstName: 'Ahmet', lastName: 'Mutlu' },
            { firstName: 'Ahmet', lastName: 'Mutlu' },
            { firstName: 'Ahmet', lastName: 'Mutlu' }
        ],
    
    });
    

    <强>列表

    var notification_list = new Ext.List({
        store: notification_list_store,
        itemTpl: '<div>{firstName}</div>',
        flex: 1
    });
    
    Ext.Viewport.add(notification_list);
    

答案 1 :(得分:0)

我发现了问题,我在模型中写了{name}但我在List中调用了{firstName},所以

Ext.define('notification_list_model', {
    extend: 'Ext.data.Model',
    config : {
    fields: [{ name: 'firstName', type: 'string' },
              { name: 'lastName', type: 'string' }]
    }
});

新模式:

  Ext.define('notification_list_model', {
            extend: 'Ext.data.Model',
             config: {
           fields: ['firstName', 'lastName'],
      }
});