我是 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/