=====================源码===============================
Ext.onReady(function(){
Ext.regModel('User',{
fields:[
{name:'name',type:'strng'},
{name:'age',type:'int'}
]
});
var userDate=[
{name:'书',age:132},
{name:'服装',age:12}
]
var memoryProxy=Ext.create('Ext.data.proxy.Memory',{
model:'User',
data:userDate
});
userDate.push({name:'箱包',age:4});
memoryProxy.update(new Ext.data.Operation({
action:'update',
data:userDate
}),function(re){},this);
memoryProxy.read(new Ext.data.Operation(),function(resule){
var dadtas=resule.resultSet.records;
Ext.Array.each(dadtas,function(record){
alert(record.get('GoodsName'));
});
});
});====================================================================
我是照着视频教程写的/可是在下面这一块出现 recs is null怎么也看不出来错在哪里
memoryProxy.update(new Ext.data.Operation({
action:'update',
data:userDate
}),function(re){},this);
/**
* @private
* Fake processing function to commit the records, set the current operation
* to successful and call the callback if provided. This function is shared
* by the create, update and destroy methods to perform the bare minimum
* processing required for the proxy to register a result from the action.
*/
updateOperation: function(operation, callback, scope) {
var i = 0,
recs = operation.getRecords(),
len = recs.length;
for (i; i < len; i++) {
recs[i].commit();
}
operation.setCompleted();
operation.setSuccessful();
Ext.callback(callback, scope || this, [operation]);
},
/**
* Currently this is a hard-coded method that simply commits any records and sets the operation to successful,
* then calls the callback function, if provided. It is essentially mocking a server call in memory, but since
* there is no real back end in this case there's not much else to do. This method can be easily overridden to
* implement more complex logic if needed.
* @param {Ext.data.Operation} operation The Operation to perform
* @param {Function} callback Callback function to be called when the Operation has completed (whether
* successful or not)
* @param {Object} scope Scope to execute the callback function in
* @method
*/
create: function() {
this.updateOperation.apply(this, arguments);
},
/**
* Currently this is a hard-coded method that simply commits any records and sets the operation to successful,
* then calls the callback function, if provided. It is essentially mocking a server call in memory, but since
* there is no real back end in this case there's not much else to do. This method can be easily overridden to
* implement more complex logic if needed.
* @param {Ext.data.Operation} operation The Operation to perform
* @param {Function} callback Callback function to be called when the Operation has completed (whether
* successful or not)
* @param {Object} scope Scope to execute the callback function in
* @method
*/
update: function() {
this.updateOperation.apply(this, arguments);
},
/**
* Currently this is a hard-coded method that simply commits any records and sets the operation to successful,
* then calls the callback function, if provided. It is essentially mocking a server call in memory, but since
* there is no real back end in this case there's not much else to do. This method can be easily overridden to
* implement more complex logic if needed.
* @param {Ext.data.Operation} operation The Operation to perform
* @param {Function} callback Callback function to be called when the Operation has completed (whether
* successful or not)
* @param {Object} scope Scope to execute the callback function in
* @method
*/
destroy: function() {
this.updateOperation.apply(this, arguments);
}, /**
* Reads data from the configured {@link #data} object. Uses the Proxy's {@link #reader}, if present.
* @param {Ext.data.Operation} operation The read Operation
* @param {Function} callback The callback to call when reading has completed
* @param {Object} scope The scope to call the callback function in
*/
read: function(operation, callback, scope) {
var me = this,
reader = me.getReader(),
result = reader.read(me.data); Ext.apply(operation, {
resultSet: result
}); operation.setCompleted();
operation.setSuccessful();
Ext.callback(callback, scope || me, [operation]);
},会发现上面的update、create、destroy都调用了同一个方法,而该方法则少了下面read方法中
var me = this,
reader = me.getReader(),
result = reader.read(me.data); Ext.apply(operation, {
resultSet: result
});
结果导致那个异常。