assigning value to Picker's selected value

edited March 2013 in Newbie Questions
how do I assign value back to picker, e.g. loading value from server and matching the content assigning into the selected item?


  • nvm i found the solution, i got messed up over components vs controls, was using the wrong properties.

    for those interested to know,

    here is how i do it, assuming you are using content as parameter to match back and assign the selected value.
    var selectedControlItem = this.findItem(this.$.yourPickerName.controls, matchingcontent) ;
    this.$.yourPickerName.setSelected( selectedControlItem );  
    // In findItem function, do a for loop with controls.length to find the matchingcontent break and return the result back to selectedControlItem;
  • thanks.
    I wonder if there is a more elegant method besides a for loop ?
    Is there any hash table implementation that does a fast lookup by value?
    Wouldn't it be helpful if the picker kind would already implement such functionality?
  • u need to check the lib\onyx\source folder and check out the picker.js, this is true till version 2.1.1 not sure if 2.2 has anything new yet.

    there's another possibility,

    this.$.yourPickerName.setSelected( this.$.selectedItemName );

    Where all your subitems are named uniquely.

    But, if u want a more custom controlled ones, you can duplicate the picker code write your own control by referencing the onyx ones. maybe called it my.picker that special method in mind.
Sign In or Register to comment.