1
votes

I have two data models: Writer.AttributValeur and Writer.Produit.

Writer.Produit has one2man relationship with Writer.AttributValeur.

I want to display (and to create/edit/delete) a list of Writer.Produit. And I want to be able to add an Writer.AttributValeur to the current Writer.Produit.

So here's what I've done: two stores:

  • the first one is linked with a grid (and a form) to display (and to create/edit/delete) a list of Writer.Produit.
  • the second one is used to display a list (only a list) of Writer.AttributValeur

In the first grid, there's a button "Add AttributValeur". When the user clicks on it, I display a Windows where there's a grid linked with the second store. If the user selects a record, and click sur ok, I can get the Writer.AttributValeur record with this code:

var currentAttribut = gridAttributs.getView()
    .getSelectionModel()
    .getSelection()[0];

I want to add this record, currentAttribut, to the Writer.Produit store.

Any idea how to do this? Following is the ExtJS declaration of my data models, and creation of my stores.

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


var storeAttributs = Ext.create('Ext.data.Store', {
    model: 'Writer.AttributValeur',
    autoLoad: true,
    autoSync: true,
    proxy: {
        type: 'ajax',
        api: {
            read: 'json/attributs/'
        },
        reader: {
            type: 'json',
            successProperty: 'success',
            root: 'data',
            messageProperty: 'message'
        }
    }
});
1

1 Answers

1
votes

What seems to be the problem? Each store has method add. Use it.