Javascript Ext.data.model不解析来自对象的数据
我有一个ExtJs模型Javascript Ext.data.model不解析来自对象的数据,javascript,extjs,model,Javascript,Extjs,Model,我有一个ExtJs模型 Ext.define('ManageProducts.model.Related', { extend : 'Ext.data.Model', fields : [ { mapping: 'sequence', name : 'sequence', type : 'int', defaultValue: nu
Ext.define('ManageProducts.model.Related', {
extend : 'Ext.data.Model',
fields : [
{
mapping: 'sequence',
name : 'sequence',
type : 'int',
defaultValue: null
},
{
mapping: 'relatedProduct.id',
name : 'relatedProduct.id',
type : 'int'
},
{
mapping: 'relatedProduct.name',
name : 'relatedProduct.name',
type : 'string'
},
{
mapping: 'relatedProduct.sku',
name : 'relatedProduct.sku',
type : 'string'
},
{
name : 'relatedProduct.pricing.price',
type : 'float',
defaultValue: null
},
{
name : 'relatedProduct.pricing.id',
type : 'int',
defaultValue: null
},
{
mapping: 'relatedProduct.status.id',
name : 'relatedProduct.status.id',
type : 'int'
},
{
name : 'relatedProduct.categories',
type : 'auto',
defaultValue: []
}
],
idProperty: 'relatedProduct.id'
});
以及必须从数据创建模型的代码
for (var i = 0; i < length; i++) {
model = Ext.ModelManager.create(data[i], 'ManageProducts.model.Related');
}
所以它是空的,除了数据根中的序列
而数据[i]是
sequence: 2
relatedProduct: Object {
categories: Array[1]
deletedAt: null
description: "Adult Male Asian Articulated Skeleton Description"
educational: "educational for Test product."
id: 6
isGroup: false
name: "Adult Male Asian Articulated Skeleton"
pricing: Object
quantity: 8
sequence: null
showEducational: false
showGroupProducts: false
sku: "SC-092-A"
status: Object
}
__proto__: Object
所以问题是为什么创建的模型是空的?
据我所知,它正确地解析来自服务器的数据。。。
但是为什么不是这样呢?您不应该使用ModelManager来创建实例。使用标准Ext.create:
var model = Ext.create('ManageProducts.model.Related', data[i]);
另一个正确的方法是:
var model = ManageProducts.model.Related.create(data[i])
第一种方法是首选的,因为如果模型类未加载,Ext会在创建之前尝试加载它,但如果使用第二种方法,并且模型类未加载,则会失败
var model = ManageProducts.model.Related.create(data[i])