【问题标题】:How to add data to list dynamical in Sencha Touch如何将数据添加到 Sencha Touch 中的动态列表
【发布时间】:2013-06-30 22:05:09
【问题描述】:

我是 Sencha Touch 的新手,我正在尝试构建一个应用程序(不是 Web 应用程序,而是使用 PhoneGap 的原生应用程序),其中包含一个应该通过单击按钮添加项目的列表。 我搜索了几天,但找不到任何有用的解决方案。

如何更改我的代码,我不必将硬编码值放入我的

data:[]
Ext.define('MyApp.store.Note', { 

extend: 'Ext.data.Store',
requires: ['MyApp.model.Note'],

config: {
model: 'MyApp.model.Note',

data:
[   
{id: 1, content: 'Blog 1', categoryid: 1, category: 'Nonsense' },
{id: 2, content: 'Blog 2', categoryid: 1, category: 'Nonsense' },
{id: 3, content: 'Blog 3', categoryid: 2, category: 'Food' }
],
}
});

我正在创建我的列表

Ext.define('MyApp.view.NoteList',{
extend: 'Ext.dataview.List',
xtype: 'notelist',
config: {

    store: "Note", //will create the store later


    itemTpl: [
        '<div>',
        '    <div>{content}</div>',
        '    <p>{category}</p>',
        '</div>'
    ],
    onItemDisclosure: function(record,btn,index) {
        this.push(Ext.create('MyApp.view.RegisterPanel'));
        //when the little arrow on the right is tapped
    }
},
});

【问题讨论】:

    标签: javascript list extjs dynamic touch


    【解决方案1】:

    您可以将商品添加到您的商店实例中。

    例子:

    var myStore = Ext.create('MyApp.store.Note');
    
    //Use add with a config object
    myStore.add({
       //your record here
       id: 1,
       content: "Blog 1",
       categoryid: 1,
       category: "Nonsense"
    });
    
    //Or create an instance of your record
    var myRecord = Ext.create('MyApp.model.Note', {
       id: 1,
       content: "Blog 3",
       categoryid: 2,
       category: "Food"
    });
    
    //Add the record to the store
    myStore.add(myRecord);
    

    【讨论】:

    • 谢谢,我要把这些放在哪里?目前我创建一个列表并像这样添加商店: store: "Note",
    • 您可以使用列表的getStore() 功能,单击按钮,然后在其中添加记录。
    • 非常感谢.. 这么简单。还没有考虑过.. :)
    猜你喜欢
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多