2013-07-03 13 views
2

我是新來的煎茶觸摸,我試圖建立包含應點擊按鈕添加項目列表中的應用程序(沒有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 
    } 
}, 
}); 

回答

2

您可以將商品添加到商店實例。

例子:

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

感謝,在這裏我必須把那些? 目前,我創建列表和添加店這樣的: 店:「注」, – mediii

+0

您可以使用您的列表的'getStore()'函數,當你點擊按鈕,然後添加你的記錄在那裏。 –

+0

非常感謝..太容易了。一直沒有想過.. :) – mediii