1. #1
    Sencha User Olivierco's Avatar
    Join Date
    Nov 2011
    Location
    Paris - France
    Posts
    65
    Answers
    3
    Vote Rating
    -1
    Olivierco is an unknown quantity at this point

      0  

    Default Answered: how to get values from a selected item into a Ext.List....

    Answered: how to get values from a selected item into a Ext.List....


    Hi,

    i have a Ext.List with data inside. very simple. is just for a test for now.
    so when i select an item of my list i want to retreive values from it.

    all i do is to get my component
    var icoList = Ext.getCmp('iconlist'); then the method getSelection();
    icoList.getSelection(); when i do that in the console, i get an Object like below. all i want to get is the value of photo: "touch/images/boss.png".
    but impossible to get this value.

    any help guys please.
    thank

    Code:
    [Object
    • _data: Object
      • id: 5
      • photo: "touch/images/boss.png"
      • __proto__: Object
    • data: Object
      • id: 5
      • photo: "touch/images/boss.png"
      • __proto__: Object
    • id: "ext-record-115"
    • modified: Object
    • raw: Object
    • stores: Array[1]
    • __proto__: Object

    Code:
                     {     xtype: 'list',
                                        id: 'iconlist',
                                        height: 50,
                                        padding: 0,
                                        scrollable: 'horizontal',
                                        inline: {
                                            wrap: false 
                                        },
                                        data: [
                                            {id: 1, photo: 'touch/images/boss.png'},
                                            {id: 2, photo: 'touch/images/boss.png'},
                                            {id: 3, photo: 'touch/images/boss.png'},
                                            {id: 4, photo: 'touch/images/boss.png'},
                                            {id: 5, photo: 'touch/images/boss.png'},
                                            {id: 6, photo: 'touch/images/boss.png'},
                                            {id: 7, photo: 'touch/images/boss.png'},
                                            {id: 8, photo: 'touch/images/boss.png'},
                                            {id: 9, photo: 'touch/images/boss.png'},
                                            {id: 10, photo: 'touch/images/boss.png'}
                                        ],
                                        itemTpl: [
                                            '<img src="{photo}">'
                                        ]
                                    }

  2. thanks,
    i found the solution:
    the solution is, as sel return an array, I just have to select the object inside the array.
    Code:
    var icoList = Ext.getCmp('iconlist'),     sel = icoList.getSelection(),
         array = sel[0];
    and then access to my value with
    array.data.photo

  3. #2
    Sencha User Olivierco's Avatar
    Join Date
    Nov 2011
    Location
    Paris - France
    Posts
    65
    Answers
    3
    Vote Rating
    -1
    Olivierco is an unknown quantity at this point

      0  

    Default


    someone?

  4. #3
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,404
    Answers
    3549
    Vote Rating
    850
    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


    getSelection() should return either a record or an array of records. If you want a field value in that record then use the get method on the record passing in the field name you want the value of.
    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.

  5. #4
    Sencha User Olivierco's Avatar
    Join Date
    Nov 2011
    Location
    Paris - France
    Posts
    65
    Answers
    3
    Vote Rating
    -1
    Olivierco is an unknown quantity at this point

      0  

    Default


    thanks,
    i found the solution:
    the solution is, as sel return an array, I just have to select the object inside the array.
    Code:
    var icoList = Ext.getCmp('iconlist'),     sel = icoList.getSelection(),
         array = sel[0];
    and then access to my value with
    array.data.photo

  6. #5
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,404
    Answers
    3549
    Vote Rating
    850
    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 should do

    Code:
    array.get('photo')
    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.

  7. #6
    Sencha User Olivierco's Avatar
    Join Date
    Nov 2011
    Location
    Paris - France
    Posts
    65
    Answers
    3
    Vote Rating
    -1
    Olivierco is an unknown quantity at this point

      0  

    Default


    i did it,
    it works, but why it's better to do array.get('photo') than array.data.photo?

  8. #7
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,404
    Answers
    3549
    Vote Rating
    850
    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


    If there is a method available, it's better to use it in general. There may be code in there to return what you expect or a property may be renamed or...
    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.

Thread Participants: 1

Tags for this Thread