i want binding context list but not working

2.7k views Asked by At

I custom object:

enter image description here

I want to fill the object but not working.

My Code:

enter image description here

  var BindingMainCat = context.binding.get("value");
                 BindingMainCat.set("AllPaymentsList[0].id", invoice_id);
                 BindingMainCat.set("AllPaymentsList[0].amount", inputs[i].value);

Please help me. Thanks

1

There are 1 answers

0
andy On

Accessors in coachview bound variables do not support complex navigation with dots and brackets. Once you obtain list itself you can use add(), remove() and put() operations on list items. You are allowed to use get() and set() on attributes of the list but not items themselves - see IBM documentation for "List operations" of binding. For example:

var list = this.context.binding.get("value");
var item0 = list.get(0);
item0.set("id", invoice_id);
item0.set("amount", inputs[i].value);

Also you can replace element of list with new one:

var list = this.context.binding.get("value");
var newItem0 = {id: invoice_id, amount: inputs[i].value};
list.put(0, newItem0);

Note that the final content of the list is the same but change notifications are different. In first example there will be two events about item properties changed, in second example there will be single event about list change - see bind() and bindAll() documentation.

Be also warned that on each step you can encounter empty values, if coachview does not have any binding then this.context.binding is undefined, if bound variable is null then this.context.binding.get("value") is null, if list has no items then list.get(0) is undefined etc.