javascript - 如何在 Sencha Touch 中添加数据到列表动态

标签 javascript list extjs dynamic touch

我是 Sencha Touch 的新手,我正在尝试构建一个应用程序(不是网络应用程序,而是 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
    }
},
});

最佳答案

您只需将商品添加到商店实例即可。

示例:

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);

关于javascript - 如何在 Sencha Touch 中添加数据到列表动态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17444216/

相关文章:

javascript - extjs中的反馈消息

javascript - ng-repeat 中 2 个不同的 div 上的 2 次 ng-click 不起作用

javascript - mongoDB 中的查找/搜索性能

javascript - 如何从自定义指令获取链接href?

python - 使用 python 重新组织具有一对多关系的列表

javascript - 为什么没有声明 global 和 this.something 变量?

javascript - 为什么 for..in 循环不遍历对象的原型(prototype)

c# - 大量 bool 值的任何拳击问题?有什么选择吗?

list - 如何在没有工作的情况下获得所有 Pod

javascript - 尝试 extjs 5 简单网格面板(示例不起作用)