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
    36,798
    Answers
    3467
    Vote Rating
    834
    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
    416
    Answers
    42
    Vote Rating
    61
    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,311
    Answers
    13
    Vote Rating
    109
    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 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

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