0

如果我有一条属于-a-store 的记录,但不知道它属于-which-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?
4

2 回答 2

1

您的记录实际上将具有.store可用于引用它所属的存储的属性 - http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Model-property-store

于 2012-08-01T13:23:38.897 回答
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())

​</p>

于 2012-08-01T15:45:48.843 回答