1. #1
    Sencha Premium Member
    Join Date
    May 2013
    Location
    Stevenage, United Kingdom
    Posts
    44
    Vote Rating
    0
    uzair.sheikh is on a distinguished road

      0  

    Default Object [object Array] has no method 'getSelection'

    Object [object Array] has no method 'getSelection'


    I am trying to get the selected index from a dataview.list but I get an error when calling getSelection() function. (Uncaught TypeError: Object [object Array] has no method 'getSelection').

    I run my app, filters my dataview.List and it gets 2 records back, click on button which has below code and it throws error.
    Error.jpg

    Here is my code:

    var value = new Array();
    var myList = new Ext.dataview.List();
    myList = Ext.ComponentQuery.query('#patientsList'); //patientList is the itemid of dataview.List component
    console.log(myList);
    value = myList.getSelection(); //it throws above error at this line
    console.log(value[0]);

    Can some one please suggest that what's wrong with the above code?
    Thanks in advance.
    -->

  2. #2
    Sencha Premium Member Salakar's Avatar
    Join Date
    Aug 2013
    Location
    Nottingham
    Posts
    90
    Vote Rating
    4
    Salakar is on a distinguished road

      0  

    Default


    Change

    PHP Code:
    value myList.getSelection(); 
    to

    PHP Code:
    value myList.getSelectionModel().getSelection(); 
    That should do it, then just use an Ext.each to go through each item. Example:

    PHP Code:
    Ext.each(value, function (item) {
         
    console.log(item);    
    }); 
    -->

  3. #3
    Sencha Premium Member
    Join Date
    May 2013
    Location
    Stevenage, United Kingdom
    Posts
    44
    Vote Rating
    0
    uzair.sheikh is on a distinguished road

      0  

    Default Thanks Salakar

    Thanks Salakar


    Thanks Salakar.

    I did try this already and I get error at getSelectionModel.

    "Uncaught TypeError: Object [object Array] has no method 'getSelectionModel'"

    I first thought that the way I am defining the instance of my dataview.list is not right, but it's actually right as when I do a console.log of the list "console.log(myList);" (just for test), I do get right number of counts for items. 3 in this case. But it's not accepting any fucntion like getSelectionModel or others.

    Error 2.png
    -->

  4. #4
    Sencha Premium Member
    Join Date
    May 2013
    Location
    Stevenage, United Kingdom
    Posts
    44
    Vote Rating
    0
    uzair.sheikh is on a distinguished road

      0  

    Default


    I think my problem is similar to this, but I still need to prove this "itemId is local to a particular container, getCmp() will only retrieve the global id for a component."

    http://stackoverflow.com/questions/14696544/uncaught-typeerror-object-object-has-no-method-getvalue

    B
    UT I think I have tried this already (I had tried billions of techniques/ways to solve this) but I will give it a try again.
    -->

  5. #5
    Sencha Premium Member Salakar's Avatar
    Join Date
    Aug 2013
    Location
    Nottingham
    Posts
    90
    Vote Rating
    4
    Salakar is on a distinguished road

      0  

    Default


    Do you have multiple elements with the itemid of #patientsList?

    Try
    myList = Ext.ComponentQuery.query('#patientsList')[0];
    as a test

    If you want I can look at your project file. PM if you want.

    Thanks
    -->

  6. #6
    Sencha Premium Member
    Join Date
    May 2013
    Location
    Stevenage, United Kingdom
    Posts
    44
    Vote Rating
    0
    uzair.sheikh is on a distinguished road

      0  

    Default


    Salakar,

    Ext.ComponentQuery.query('#patientList') ==> This is not a problem as I get the list component back fine and I can see this in console.log. The problem is, I can't call any function on this returned LIST component.
    -->

  7. #7
    Sencha Premium Member Salakar's Avatar
    Join Date
    Aug 2013
    Location
    Nottingham
    Posts
    90
    Vote Rating
    4
    Salakar is on a distinguished road

      1  

    Default


    Sorry if it seems I'm less than helpful, I'm just trying to understand your code.

    Code:
    var myList = Ext.ComponentQuery.query('#patientsList')[0]; //patientList 
    console.log(myList); //works
    var value = myList.getSelection(); //works
    // loop through selection
    Ext.each(value, function (item) {
         console.log(item.data);    
    });
    Created a dummy project with the above code in my button tap event and it works.

    As mentioned in the sencha docs Ext.ComponentQuery will return an array of components, therefore you cannot call the list methods on the array, adding the [0] (selecting first array item) at the end made it work for me, as said in previous post.

    Untitled.png


    Hope this helps
    -->

  8. #8
    Sencha Premium Member
    Join Date
    May 2013
    Location
    Stevenage, United Kingdom
    Posts
    44
    Vote Rating
    0
    uzair.sheikh is on a distinguished road

      0  

    Default


    Thanks Salakar.

    adding [0] at the end has given me fair amount of progress as I am not getting error on calling getSelection() function now

    I can now see getting the selected items in the filed but it's only giving [object Object] as output, which I think something to do with output the data in right format as it outputs an array.

    Progress.jpg
    -->

  9. #9
    Sencha Premium Member
    Join Date
    May 2013
    Location
    Stevenage, United Kingdom
    Posts
    44
    Vote Rating
    0
    uzair.sheikh is on a distinguished road

      0  

    Default


    Salakar,

    Sorry, just seen your latest post and I would say that 'I had missed the basic concept
    ). I did the similar thing in another part of the same project.


    Ext.each(value, function (item) { console.log(item.data);Thanks for your help. I will give it a go now.
    -->

  10. #10
    Sencha Premium Member
    Join Date
    May 2013
    Location
    Stevenage, United Kingdom
    Posts
    44
    Vote Rating
    0
    uzair.sheikh is on a distinguished road

      0  

    Default


    All working as a charm . Thanks

    Quote Originally Posted by Salakar View Post
    Sorry if it seems I'm less than helpful, I'm just trying to understand your code.

    Code:
    var myList = Ext.ComponentQuery.query('#patientsList')[0]; //patientList 
    console.log(myList); //works
    var value = myList.getSelection(); //works
    // loop through selection
    Ext.each(value, function (item) {
         console.log(item.data);    
    });
    Created a dummy project with the above code in my button tap event and it works.

    As mentioned in the sencha docs Ext.ComponentQuery will return an array of components, therefore you cannot call the list methods on the array, adding the [0] (selecting first array item) at the end made it work for me, as said in previous post.

    Attachment 46192


    Hope this helps
    -->

Thread Participants: 1