请试试这个例子。
打开控制台,运行 jsFiddle,更改属性值,然后单击“将状态写入控制台”。
为什么商店仍然报告零更新记录?它知道该属性的新值。
这是 JsFiddle 中的 Ext JS 4.2 代码:
Ext.onReady(function() {
Ext.define('KitchenSink.view.grid.PropertyGrid', {
extend: 'Ext.container.Container',
requires: [
'Ext.button.Button',
'Ext.grid.property.*',
'Ext.layout.container.VBox',
'Ext.layout.container.HBox'
],
xtype: 'property-grid',
height: 275,
width: 300,
layout: {
type: 'vbox',
align: 'stretch'
},
initComponent: function(){
Ext.apply(this, {
items: [{
xtype: 'container',
layout: 'hbox',
margin: '0 0 10 0',
defaultType: 'button',
items: [{
text: 'Write state to console',
margin: '0 0 0 10',
scope: this,
handler: this.onWriteStateClick
}]
}, {
xtype: 'propertygrid',
source: {
weight: 0.01,
distance: 1
}
}]
});
this.callParent();
},
onWriteStateClick: function(){
var grid = this.down('propertygrid');
var store = grid.getStore();
console.log("Number of new records: " + store.getNewRecords().length);
console.log("Number of updated records: " + store.getUpdatedRecords().length);
console.log("Number of deleted records: " + store.getRemovedRecords().length);
store.each(function (rec) {
console.log("store says --> key: " + rec.get("name") + ", value: " + rec.get("value"));
});
//var source = grid.getSource();
//Object.keys(source).forEach(function(key) {
// console.log("source says --> key: " + key + ", value: " + source[key]);
//});
},
});
Ext.create('KitchenSink.view.grid.PropertyGrid', { renderTo: Ext.getBody() });
});