嗨 StackOverflow 用户!
我有一些 json 数据,应该将其加载到具有三个关联的模型中。其中两个是好的,但第三个是行不通的。
这是来自服务器的 json 回复:http: //pastebin.com/geL16BvL
主要型号:
Ext.define('Invoice', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'invoice_id', type: 'string'},
{name: 'invoice_date', type: 'date', dateFormat: 'time'},
{name: 'invoice_due_date', type: 'date', dateFormat: 'time'},
{name: 'invoice_year_index', type: 'int'},
{name: 'invoice_total', type: 'number'},
{name: 'invoice_vat', type: 'number'},
{name: 'invoice_delivery', type: 'number'},
{name: 'invoice_total_cost', type: 'number'},
{name: 'invoice_payment_method', type: 'string'},
{name: 'invoice_status', type: 'string'},
{name: 'invoice_discount', type: 'number'},
{name: 'invoice_discount_type', type: 'string'},
{name: 'invoice_fixed_charges', type: 'number'},
{name: 'invoice_currency_code', type: 'string'},
{name: 'invoice_currency_symbol', type: 'string'},
{name: 'localization_data_source', type: 'string', mapping: 'data_source.data_source_name'}
],
associations: [
{model: 'Contractor', name: 'contractor', type: 'hasOne'},
{model: 'SalesRepresentative', name: 'salesRepresentative', type: 'hasOne', associationKey: 'salesRepresentative'},
{model: 'InvoiceItem', name: 'invoiceItems', type: 'hasMany'}
]
});
两个工作:
Ext.define('InvoiceItem', {
extend: 'Ext.data.Model',
belongsTo: 'Invoice',
fields: [
{name: 'id', type: 'int'},
{name: 'invoice_id', type: 'string'},
{name: 'item_variation_id', type: 'string'},
{name: 'item_quantity', type: 'number'},
{name: 'item_name', type: 'string'},
{name: 'item_price', type: 'number'},
{name: 'item_value', type: 'number'},
{name: 'item_position_vat', type: 'number'},
{name: 'item_vat', type: 'number'},
{name: 'item_tax', type: 'number'},
{name: 'item_category_name', type: 'string'},
{name: 'item_discount', type: 'number'},
{name: 'item_price_before_discount', type: 'number'}
]
});
Ext.define('Contractor', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'contractor_id', type: 'string'},
{name: 'contractor_email', type: 'string'},
{name: 'contractor_status', type: 'string'},
{name: 'contractor_registered', type: 'date', dateFormat: 'time'},
{name: 'contractor_name', type: 'string'},
{name: 'contractor_company', type: 'string'},
{name: 'contractor_company_vat_no', type: 'string'},
{name: 'contractor_phone', type: 'string'},
{name: 'contractor_address', type: 'string'},
{name: 'contractor_city', type: 'string'},
{name: 'contractor_postcode', type: 'string'},
{name: 'contractor_country', type: 'string'}
]
});
第三个 - 销售代表:
Ext.define('SalesRepresentative', {
extend: 'Ext.data.Model',
belongsTo: 'Invoice',
fields: [
{name: 'id', type: 'int'},
{name: 'representative_id', type: 'string'},
{name: 'representative_name', type: 'string'},
{name: 'representative_email', type: 'string'}
]
});
当我使用 InvoiceDetails 访问 Contractor 或 store 时,一切都很好。但是,当我尝试通过以下方式访问 SalesRepresentative 时:
Ext.getStore('invoicesStore').getAt(0).getSalesRepresentative()
我收到“TypeError: url is return url + (url.indexOf('?') === -1 ? '?' : '&') + string;”
我很确定关系有问题,但我找不到让它工作的方法。