ExtJS, хранилище, HasMany — BelongsTo и процесс обновления: как?

У меня есть две модели данных: Writer.AttributValeurи Writer.Produit.

Writer.Produit имеет связь HasMany/ BelongsToс Writer.AttributValeur.

Таким образом, определение выглядит следующим образом:

Ext.define('Writer.AttributValeur', {
    extend: 'Ext.data.Model',
    fields: [{
            name: 'id',
            type: 'int',
            useNull: true
        },  
        'description',
        'val'
    ],  
    belongsTo: 'Writer.Produit'
});

Ext.define('Writer.Produit', {
    extend: 'Ext.data.Model',
    fields: [{
            name: 'id',
            type: 'int',
            useNull: true
        },  
        'titre',
        'description'
    ],
    hasMany: {
        model: 'Writer.AttributValeur',
        name: 'attributs'
    }   
});

var store = Ext.create('Ext.data.Store', {
    model: 'Writer.Produit',
    autoLoad: true,
    autoSync: true,
    proxy: {
        type: 'ajax',
        api: {
            read: 'json/liste_view/',
            create:  'json/item/?mode=create',
            update:  'json/item/?mode=update',
            destroy: 'json/item/?mode=destroy'
        },
        reader: {
            type: 'json',
            successProperty: 'success',
            root: 'data',
            messageProperty: 'message'
        },
        writer: {
            type: 'json',
            writeAllFields: true,
            root: 'data'
        }
    }
});

Теперь, когда я прочитал файле с запросом «Produits», есть ответ AJAX, который отлично работает:

AJAX answer that works perfectly

И в каждой «строке» есть много Writer.AttributValeur(я назвал их «атрибутами», см. рисунок ):

many Writer.AttributValeur

Проблема заключается в том, что когда я вставляю Writer.AttributValeurв это поле «атрибуты», вот так:

form.getRecord().attributs().add(newrecord);

Это работает отлично, но когда я вызываю store.sync()ничего не происходит, поэтому я вручную помечаю запись как грязная:

form.getRecord().attributs().add(newrecord);
form.getRecord().setDirty();
form.getRecord().store.sync();

Теперь она отправлена, но атрибуты не отправляются! См.:

Showing that the attributs are not sent

Как мне "добавить" это в процесс обновления?

8
задан 28 March 2012 в 08:54
поделиться