PDA

View Full Version : assign value to item selector dynamcially



hieu79vn
16 Jul 2012, 4:14 AM
Hi

I tried to assigne value to item selector dynamically but it didn't show the value on the right side

value: [this.record.get('send_to').split('###')[0]]
///this.record.get('send_to').split('###')[0] return 'Buyer','Document controller','Discipline Engineer','ABC'

if i assign statically like this
value : ['Buyer','Document controller','Discipline Engineer','ABC']
it run

Do you know why?

tvanzoelen
16 Jul 2012, 6:52 AM
What does it show. Nothing?

hieu79vn
16 Jul 2012, 6:57 AM
yes, nothing in the right side panel (selected value)

scottmartin
16 Jul 2012, 7:08 AM
If you assign it to a var first .. does it help? Timing issue?

Scott.

hieu79vn
16 Jul 2012, 11:20 PM
Hi Scott,
Yes, you are correct. If I assign it to a var first, it runs well. But I cannot do like that because I have many instance of form which contains the itemselector.
Do you have any idea?

Thank you

scottmartin
17 Jul 2012, 7:12 AM
You could use setValue to set/update the value at runtime once the values are populated. Th other option would be to create an object that gets populated at startup and use that to populate your component.

Scott.

hieu79vn
18 Jul 2012, 12:27 AM
Hi Scott

I tried to use setValue as you said but it seems that I can only set one value. For example
this.setValue('engineer');

how can I set 2 selected value?
for example: this.setValue('engineer','buyer'); or something like that?
Thanks

hieu79vn
18 Jul 2012, 8:28 AM
Hi Scott,
I'm sorry for asking many question for itemselector.
I have one more question.

If I set a value hardcoded like this
this.itemselectoruser.setValue(['buyer','controller']);
it runs well
But if I use a variable
var str = '\'buyer\',\'controller\'';
this.itemselectoruser.setValue([str]);
It doesn't work.

Please tell me how to add a variable to setValue's parameters. Thank you for your help

scottmartin
21 Jul 2012, 10:49 AM
Try the following:



var str = ['AL','AZ']; // array
combo.setValue(str);


Scott

hieu79vn
23 Jul 2012, 1:51 AM
Thankyou Scott
I did like this

var datar = new Array();
for (var i = 0; i < arr.length; i++) {
datar.push(arr[i]);
}
this.itemselectorsendto.setValue(datar);