2012-08-01 72 views
0

如果我有一条属于-a-商店的记录,但它不属于它所属的商店,我该如何删除该记录?对商店中的记录执行en编辑

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? 

回答

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