2012-08-01 68 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())