0

こんにちは、StackOverflow ユーザーです。

3 つの関連付けを持つモデルにロードする必要がある json データがいくつかあります。そのうちの 2 つは問題ありませんが、3 つ目は機能しません。

これはサーバーからの 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'}
]

});

2 つの作業:

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'}
    ]
});

そして 3 つ目 - 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()

「TypeError: url は return url + (url.indexOf('?') === -1 ? '?' : '&') + string; です。」

関係に何か問題があると確信していますが、それを機能させる方法が見つかりません。

4

1 に答える 1

2

あなたのストアはおそらく AJAX プロキシ (またはExt.data.proxy.Serverから派生したその他のプロキシ) を使用し、サーバー リクエストを介して営業担当者のレコードを読み込もうとしますが、モデルで URL を見つけることができません。

追加してみる

proxy: {
    type: 'memory'
}

あなたのモデルに。

于 2013-10-14T13:28:58.677 に答える