【问题标题】:ExtJS models associationExtJS 模型关联
【发布时间】:2013-10-14 12:22:33
【问题描述】:

您好 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()

我收到 “类型错误:网址是 返回 url + (url.indexOf('?') === -1 ? '?' : '&') + string;"

我很确定关系有问题,但我找不到让它起作用的方法。

【问题讨论】:

    标签: extjs models


    【解决方案1】:

    您的商店可能使用 AJAX 代理(或派生自 Ext.data.proxy.Server 的任何其他代理)并尝试通过服务器请求加载销售代表记录,但无法在模型上找到 URL。

    尝试添加

    proxy: {
        type: 'memory'
    }
    

    到你的模型。

    【讨论】:

      猜你喜欢
      • 2018-05-17
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-01
      • 1970-01-01
      • 2016-05-24
      相关资源
      最近更新 更多