如果我有一个属于-a- store的记录,但不知道它属于哪个商店,我该如何删除该记录?
例如
var store = Ext.create('Ext.data.Store',{
model:'Pies'
data:{Type:123,Name:"apple"}
})
var record = store.getAt(0)
//How do I store.remove(record); without actually having the store record handy?
答案 0 :(得分:1)
您的记录实际上会包含属性.store
,您可以使用该属性来引用它所属的商店 - http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Model-property-store
答案 1 :(得分:1)
这是一个删除给定记录的Ext JS代码示例。该记录引用了它所属的商店。使用该商店参考与商店的删除方法相结合,您可以删除下面编码的记录。
运行下面粘贴的代码: http://jsfiddle.net/MSXdg/
示例代码:
Ext.define('Pies', {
extend: 'Ext.data.Model',
fields: [
'Type',
'Name'
]
})
var pieData = [{
Type:123,
Name:'apple'
}];
var store = Ext.create('Ext.data.Store',{
model:'Pies',
data: pieData,
proxy: {
type: 'memory'
}
})
var debug = Ext.fly('debug');
if (debug) {
debug.setHTML('Record count: ' + store.getCount());
}
console.log('Record count: ' + store.getCount())
var record = store.getAt(0);
// remove the record
record.store.remove(record);
// display the store count to confirm removal
if (debug) {
debug.setHTML(debug.getHTML() + '<br />Record count after removal: ' + store.getCount());
}
console.log('Record count after removal: ', store.getCount())