2013-10-14 49 views
0

您好StackOverflow用戶!ExtJS模型協會

我有一些json數據,應該將其加載到具有三個關聯的模型中。其中兩個是okey,但第三個不行。

下面是來自服務器的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'} 
    ] 
}); 

和第三一個 - 的SalesRepresentative:

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存儲任何工作真的很好。但是,當我嘗試通過訪問的SalesRepresentative例如:

Ext.getStore('invoicesStore').getAt(0).getSalesRepresentative() 

我收到 「類型錯誤:網址是 返回URL +(url.indexOf()=== -1 '?'? '?' :'&')+ string;「

我敢肯定,有些事情與關係錯了,但我找不到辦法使它工作。

回答

2

您的商店可能使用AJAX代理(或從Ext.data.proxy.Server派生的任何其他代理),並嘗試通過服務器請求加載銷售代表記錄,但未能在模型上找到URL。

嘗試增加

proxy: { 
    type: 'memory' 
} 

到模型。

+0

我會試試看。謝謝。 – Mateusz