Get value from Store

January 6th, 2009
  • Im trying to get a value from store to do an if/else. But I always get "undefined".


    ComboOne.on('select', function() {
    var combo = ComboOne.getValue();
    DSOne_data = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({url: 'extractFunc.php?p=fase1&id='+combo, waitMsg: 'Searching...'}),
    reader: new Ext.data.JsonReader({},['id', 'name']),
    remoteSort: false
    });

    DSOne_data.on('load', function() {
    test = DSOne_data.getById('name');
    Ext.MessageBox.alert('Ok', 'Data '+test);
    //HERE ALWAYS GET undefined
    if(test == undefined){
    Ext.MessageBox.alert('Ok', 'Data undefined');
    }else{
    Ext.MessageBox.alert('Ok', 'Data '+test);
    }
    });
    DSOne_data.load();
    });


    Im I doing something wrong ?

    The Store has data, i've checked on FF, but I can't get this field to do my if/else.

    Thanks in advice.


  • I still can't get the value :(


  • You are attempting to retrieve an id of name.

    test = DSOne_data.getById('name');


    I don't see an id of name in your JSON. To retrieve the television record you would do the following:

    test = DSOne_data.getById('5631');


    Then you could retrieve the name of it like so:

    test.get('name');


  • Ok.

    This is my Json

    [{"id":"5361","name":"Television"}]


    I want to know if name is setted cause if isnt I need to call other Json like this:

    [{"id_instalation":"1","site":"5313","nametwo":"Radio","status":"Evaluation","datestart":"2007-07-11","dateend":"0000-00-00","type":"Expansion","subtype":"C1","super":"Creed","enterprise":"crook","text":" tyest","code":"","socode":"","datesocode":"0000-00-00","wo":"","datewo":"0000-00-00","conf":"","confg":"0","conff":"","mat":"","datemat":"0000-00-00","datemata":"0000-00-00","stor":"","dateremat":"0000-00-00","pep":"","datepep":"0000-00-00","dateendpep":"0000-00-00","oc":"","dateoc":"0000-00-00","ocnum":"","ocdateinst":"0000-00-00","ocdas":"","dateocdas":"0000-00-00","amount":"","pen":"","ocdesc":"","comp":"0","subt":"0000-00-00","energy":"0000-00-00","tram":"","datetram":"0000-00-00","datetramen":"0000-00-00","cnf":"","datecnf":"0000-00-00","date":"","searchdate":"0000-00-00","surv":"","survdate":"0000-00-00","negotia":"","datenegotia":"0000-00-00","contractdate":"0000-00-00","antipro":"","dateantipro":"0000-00-00","plain":"","dateplain":"0000-00-00","dococ":"","dateocdoc"
    :"0000-00-00","matedoc":"","matedate":"0000-00-00","med":"","datemed":"0000-00-00","pic":"","datepic":"0000-00-00","ada":"","dateada":"0000-00-00"}]


    Thanks in advice.


  • test = DSOne_data.getById('5631');


    This works only if I ask if(String(test) == String('undefined')){ and works for me... but don't give me the value.

    If I add test.get('name') says that test don't has properties.

    Thanks ! :D


  • Now I do this for take the real value in combo.

    function realSelected(Cntrl,data){
    for(i=0;i if(Cntrl.options[i].text == String(data)){
    Cntrl.selectedIndex = i;
    }
    }
    }


    So I just send the cntrl combo and data to evaluate and give me the selected item on my combo.

    Ty.


  • JsonReader has a configurable id field which you need to set. Try this:

    reader: new Ext.data.JsonReader({id: 'id'},['id', 'name']),


  • I mocked up a simple test case locally using your source and it works.... Can you post your updated source again?


  • ComboOne.on('select', function() {
    var combo = ComboOne.getValue();
    DSOne_data = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({url: 'extractFunc.php?p=fase1&id='+combo, waitMsg: 'Searching...'}),
    reader: new Ext.data.JsonReader({},['id', 'name']),
    remoteSort: false
    });

    DSOne_data.on('load', function() {
    test = DSOne_data.getById(combo);
    Ext.MessageBox.alert('Ok', 'Data '+test);
    if(String(test) == String('undefined')){
    Ext.MessageBox.alert('Ok', 'Data undefined');
    }else{
    Ext.MessageBox.alert('Ok', 'Data '+test);
    }
    });
    DSOne_data.load();
    });


    Im doing it like this now and it works... but now I'm having other issue.

    The thing is that I want to select a value from ComboBox but with this:

    combo.setValue(DSOne.getAt(0).data.id);


    My combo takes the value and not the text. Is like the value of the option and not the text who defines him.()

    I've tried with:

    combo.selectByValue(DSOne.getAt(0).data.id);

    And this works but still has the number on my combo and not the text =/

    Any ideas ?


  • ???... I didnt use that code... my code up is the one what im using now.

    The thing that I want to do now is to set a combo with a value obtained with Store.
    With the code above, I can see if test is a [Object object] or undefined so that's the way who works for me... now I can set my combo with this value but I can't set the value from combo itselfs... Is like I can write into combo a text without value... so that doesnt work for me.

    Thanks in advice.


  • JsonReader has a configurable id field which you need to set. Try this:

    reader: new Ext.data.JsonReader({id: 'id'},['id', 'name']),


    But back to the drawing board.... what are you actually trying to accomplish here with this code?


  • Can you post a sample of what your JSON looks like?


  • You could always use the value configuration option of ComboBox.

    getById is not going to work because you never told the record what the id was!







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Get value from Store , Please add it free.