0
votes

I have a grid panel and i make a function inside that like

myFunction: function(variable){ 
    grid.getStore().each(function(item) {
        if (item.get('value') == variable) {
             alert('run'); // running
             return true; // but not return true
        }
    });
    return false;
}

But when i using

alert(grid.myFunction('abc')); // always return false Although alert('run'); running

How to fix that thank

1

1 Answers

1
votes

You are only returning true inside of the each function. This will break you out of the inner function, but will not return true from the outer function. To get what you want, you could use a variable that you set outside of each, then return that at the end:

myFunction: function(variable){
    var found = false;
    grid.getStore().each(function(item) {
        if (item.get('value') == variable) {
            alert('run');
            found = true;
            return false;
        }
    });
    return found;
}

Also note that returning false from store.each aborts the iteration, which is what you would want to do after finding your record, so I've added that in there too. See docs here: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Store-method-each