extjs 4 : get store record values

18,392

What i don't get is the way you have used myStore. You have used it both ways as a string as well as a variable. Which is it? If its a string, then myStore.load() will not work. If its a variable, you need to lose the quotes on Ext.StoreMgr.lookup(myStore). Where is the store variable being declared?

Share:
18,392
salamey
Author by

salamey

Updated on June 04, 2022

Comments

  • salamey
    salamey almost 2 years

    my json data looks like this :

    ({"success": "true", "message" : "OK","data":[{"id_metric":"1","name_filter":"doc filter","type_guicomp":"combobox"},{"id_metric":"1","name_filter":"severity","type_guicomp":"combobox"}]})
    

    I'd like to be able to retrieve the "type_guicomp" field value for the "id_metric" = 1 , so the result would be : "type_guicomp":"combobox" and "type_guicomp":"combobox".

    I do this because I need the value "combobox" to assign it to a variable. I've tried several things including :

    myStore.load({
            scope: this,
            callback : function(record, operation, success) {
                console.log(record);
                console.log(record.data);
                }
    

    And :

    var index = Ext.StoreMgr.lookup("myStore").findExact('id_metric',1);
    var rec = Ext.StoreMgr.lookup("myStore").getAt(index);
    console.log(rec);
    

    These solutions return undefined or null. So when I did this in the callback :

    var i = myStore.getCount();
    console.log(i);
    

    It returned 0. But when I check the json output, it's not empty and there's actually data in it.

    What am I doing wrong? Please any help would be appreciated.

    EDIT

    My store looks like this :

    Ext.define('Metrics.store.MyStore', {
    extend: 'Ext.data.Store',
    model: 'Metrics.model.MyModel',
    autoLoad: true,
    idProperty: 'id_metric',
    proxy : {
        type : 'ajax',
        actionMethods : 'POST',
        node : 'id_metric',
        api : {
        read : 'gui_comp_items.php' //the php script that gets data from db
        },
        reader: {
            type: 'json',
            successProperty: 'success',
            messageProperty: 'message',
            root: 'data'
        }
    }
    });
    

    My Model :

    Ext.define('Metrics.model.MyModel', {
    extend: 'Ext.data.Model',
    fields: [
    {name : 'id_metric', type : 'int'},
    {name : 'name_filter', type : 'string'},
    {name : 'type_guicomp', type : 'string'},
    {name : 'value', type : 'string'}]  
    });
    
  • salamey
    salamey about 11 years
    I have declared : var myStore = this.getMyStore();
  • Aashray
    Aashray about 11 years
    Have you created the store and model using Ext.create? From my understanding, these are just definitions, you need to create them once they have been defined.
  • salamey
    salamey about 11 years
    I'm using the Extjs 4 MVC architecture, the store and model are defined then used by the controller. I don't think that's the problem.