0

我的代码是,

  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 文本不打印

4

2 回答 2

0

不要忘记使用sencha 文档

  1. 模型字段应该在配置中。
  2. 在商店型号名称应该是一个字符串

模型

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);
于 2013-08-15T09:29:37.397 回答
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'],
      }
});
于 2013-08-15T12:01:59.067 回答