안녕하세요 StackOverflow 사용자!ExtJS 모델 연관
몇 가지 json 데이터가 있습니다.이 데이터는 3 회의 간섭이있는 모델에로드해야합니다. 그 중 두 개는 okey이지만 세 번째 것은 작동하지 않습니다. http://pastebin.com/geL16BvL
메인 모델 : 여기
은 서버에서 JSON 응답의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에 액세스하려고 할 때 : 홈페이지 반환 URL + (url.indexOf (입니다) === -1 :
Ext.getStore('invoicesStore').getAt(0).getSalesRepresentative()
나는 형식 오류가 " 를 받고있어 '?'? '?' : '&') + 문자열; "
나는 관계에 문제가 있다고 확신하지만 제대로 작동하도록 만들 수는 없습니다.
시도해 보겠습니다. 감사. – Mateusz