我正在尝试针对Restful RubyonRails后端创建一个简单的ExtJS5应用程序.出于某种原因,当我实例化模型时,ExtJs使用模型(和计数器)的名称填充"idProperty"字段.例如
{ "Traffic_id": "MyApp.model.Person-1", "EXTERNAL_ID":0,...
我认为"idProperty"字段本质上是数据记录的主键,通常在将记录插入数据库时自动设置(自动增量)
因此,此字段应为null或类似,因为模型尚未添加到商店并同步到后端.
更令人惊讶的是,该字段定义为'int',ExtJS将字符串放入其中!
有人能告诉我发生了什么事吗?
彼得
下面是一个小提琴的app.js:
Ext.application({
name : 'Fiddle',
launch : function() {
var model = Ext.create('MyApp.model.Person');
Ext.Msg.alert('Fiddle', JSON.stringify(model.data));
}
});
Ext.define('MyApp.model.Person', {
extend: 'Ext.data.Model',
idProperty: 'Traffic_id',
proxy: {
type: 'rest',
// url: '/traffics.json',
format: 'json',
api: {
create: 'traffics',
read: 'traffics',
update: 'traffics/edit',
destroy: 'traffics'
},
reader: {
type: 'json',
rootProperty: 'traffic',
successProperty: 'success',
messageProperty: 'message'
},
writer: {
type: 'json',
//writeAllFields : false,
//encode: true,
rootProperty: 'traffic'
},
afterRequest: function(req, res) …Run Code Online (Sandbox Code Playgroud)