1. #1
    Sencha User
    Join Date
    Oct 2010
    Location
    Cusco
    Posts
    11
    Vote Rating
    0
    jorgelive is on a distinguished road

      0  

    Default Unanswered: Belongs to -> Empty data Ext 4.2 MVC

    Unanswered: Belongs to -> Empty data Ext 4.2 MVC


    I’m trying to show parent record data in my grid using “belongs to “relation in MVC, but getter object for record is empty (it shows only raw data).


    Is it necessary to load parent model’s store? Chidren’s json data contains all data I need, and loading all parents store would increase traffic for the application.


    I set it to auto load but it is the same.


    When autoload set to false parent’s store is empty, it is only part of the record in the children’s store, where related (parent) data is supposed to be stored?,


    Do I need to use setter function to persist raw data to the store?


    Parent's Model:
    Code:
    Ext.define('MyApp.model.FfileModel', {
        extend: 'Ext.data.Model',
    
    
        uses: [
            'MyApp.model.FservicioModel'
        ],
    
    
        fields: [
            {
                name: 'id',
                type: 'int'
            },{
                name: 'nombre',
                type: 'string'
            },{
                name: 'observaciones',
                type: 'string'
            },
    ],
    
    
        hasMany: {
            associationKey: 'fservicios',
            model: 'MyApp.model.FservicioModel',
            autoLoad: false,
            foreignKey: 'ffile_id'
        }
    });



    Children's model:
    Code:
    Ext.define('MyApp.model.FservicioModel', {
        extend: 'Ext.data.Model',
    
    
        uses: [
            'MyApp.model.FfileModel'
        ],
    
    
        fields: [
            {
                name: 'id',
                type: 'int'
            }, {
                name: 'ffile_id',
                type: 'int'
            },
    ],
    
    
        belongsTo: {
            associationKey: 'ffile',
            model: 'MyApp.model.FfileModel',
            foreignKey: 'ffile_id',
            getterName: 'getFfile',
            setterName: 'setFfile'
        }
    });

    Children's json
    Code:
    { servicios:[
        {
        "id": 1,
        "ffile_id":1,
        "ffile":[
            {
            id:1,
            nombre:"xxx",
            observaciones:"xxx"
            }
            ]
        },
        {"id": 2,
          "ffile_id":1,
           "ffile":[
            {
            id:1,
            nombre:"xxx",
            observaciones:"xxx"
            }
            ]
        },
    ]}

    Renderer;
    Code:
    renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
        return record.getFfile().get('nombre');
    }

    Content of getter object:
    Code:
    ({raw:[{id:1, nombre:"xxx", observaciones:"xxx"}], modified:{}, data:{nombre:"",  observaciones:"" }, hasListeners:{}, events:{}, stores:[], phantom:false, internalId:"ext-record-1", id:"MyApp.model.FfileModel-ext-record-1"})

  2. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    4,900
    Answers
    369
    Vote Rating
    176
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      0  

    Default


    Unless you require the extended functionality of model associations you may very well be able to get away with a much smaller code footprint. See the example below:

    Client code
    Code:
    Ext.define('MyApp.model.FfileModel', {
        extend: 'Ext.data.Model',
        fields: ['ffile_id', 'ffile', 'id'],
        proxy: {
            type: 'ajax',
            url: 'data/json.json',
            reader: {
                type: 'json',
                root: 'servicios'
            }
        }
    });
    
    
    
    
    var store = Ext.create('Ext.data.Store', {
        model: 'MyApp.model.FfileModel',
        autoLoad: true
    });
    
    
    Ext.widget('gridpanel', {
        renderTo: document.body,
        height: 200,
        width: 200,
        store: store,
        columns: [{
            text: 'ffile_id',
            dataIndex: 'ffile_id'
        }, {
            text: 'nombre',
            dataIndex: 'ffile',
            renderer: function (val, meta, rec) {
                return rec.get('ffile')[0].nombre;
            }
        }]
    });
    Server response:
    Code:
    {
        servicios: [{
            "id": 1,
            "ffile_id": 1,
            "ffile": [{
                id: 1,
                nombre: "xxx",
                observaciones: "xxx"
            }]
        }, {
            "id": 2,
            "ffile_id": 1,
            "ffile": [{
                id: 1,
                nombre: "xxx",
                observaciones: "xxx"
            }]
        }]
    }
    Are you a Sencha products veteran who has wondered what it might be like to work at Sencha? If so, please reach out to our recruiting manager: sheryl@sencha.com

    C
    heck out all of the 2013 SenchaCon presentations here:
    http://www.sencha.com/blog/senchacon...now-available/

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi