Failed to save extjs file

ExtJS Model fields have a display option.

fields: [
        {name: 'brandId', mapping:'brand.id',   type: 'int'},
        {name: 'brandName', mapping:'brand.name', type: 'string'},

The problem is that if the response from the server does not contain any field (brand fields in my example) and the display from the internal fields is determined, Ext Store silently downloads the records.

Does anyone have a problem with this? It's some kind of mistake?

UPDATE To make it clear: suppose I have ten fields in my model. The response from the server has nine fields, one missing. If there is no nested matching in this field (matching: "xyz"), everything is fine - the record loads the record, the field is empty. But if this field should be loaded from some nested field and has a matching parameter - the store does NOT load ANYTHING.

UPDATE 2 I found code that causes problems. The thing is, when Ext tries to load a field from Json, it performs a check like this

(source["id"] === undefined) ? __field0.defaultValue : source["id"]

But when there is a mapping option (mapping 'brand.id) in the field, Reader does it this way

(source.brand.id === undefined) ? __field20.defaultValue : source.brand.id

which causes an error if the source does not have a brand field.

If you have the same problems as me: you can fix this by overriding the Ext.data.reader.Json method of createFieldAccessExpression

+3
source share
2 answers

I agree that Ext should only load this field, not the entire record. One option, which is small but should work, uses a function instead mapping:

{
    name: 'brandId',
    mapping: function(data, record) {
        return data.brand && data.brand.id;
    }
}

( , , ), , , , , , .

+2

, mapping nesting: . , .

0

All Articles