1. #1
    Sencha User yuryn1961's Avatar
    Join Date
    Nov 2011
    Posts
    6
    Vote Rating
    0
    yuryn1961 is on a distinguished road

      0  

    Default Unanswered: Select from array, is it possible?

    Unanswered: Select from array, is it possible?


    Hi,

    I've got a javascript array:

    var x = [
    {id:22, name:'Merry'},
    {id:26, name:'Poppins'},
    {id:345, name:'Popcorn'}
    ];

    Is it possible to create with Sencha Core a method which returns a sub array by a given param, like SQL command (select elements where name like '%Pop%').

    function x(x, 'Pop') { } will returns:
    [
    {id:26, name:'Poppins'},
    {id:345, name:'Popcorn'}
    }.
    Any help will be appreciate.
    Thanks

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,700
    Answers
    3356
    Vote Rating
    749
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You can use RegEx but you need something to look at the object. We have one for an array of strings.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Ext JS Premium Member burnnat's Avatar
    Join Date
    Jun 2011
    Posts
    410
    Answers
    40
    Vote Rating
    55
    burnnat is a jewel in the rough burnnat is a jewel in the rough burnnat is a jewel in the rough burnnat is a jewel in the rough

      0  

    Default


    What you're looking for, I think, is the function Ext.Array.filter which can be used like so:

    Code:
    var pops = Ext.Array.filter(array, function(item) {
        return item.name.indexOf('Pop') != -1;
    });

  4. #4
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,188
    Answers
    7
    Vote Rating
    102
    LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light

      0  

    Default


    You can also take a look at the MixedCollection class, which is a beefed up Array.

    See how you can filter data in stores:

    http://docs.sencha.com/ext-js/4-0/#!...-method-filter

  5. #5
    Sencha User yuryn1961's Avatar
    Join Date
    Nov 2011
    Posts
    6
    Vote Rating
    0
    yuryn1961 is on a distinguished road

      0  

    Default


    Thanks burnnat, I tried it, it does not work with Ext Core (as the LesJ's solution), but your reply helped me.
    Here is my code:
    function selectFromArray(arr, s){
    var result=new Array();
    Ext.each(arr, function(item){
    if(item.name.indexOf(s) > -1){
    result.push(item);
    }
    });
    return result;
    }

    Thanks to all again

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar