Binding arrays instead of objects

edited December 2013 in Enyo 2.4
Hello !
I'm evaluating enyo for future projects and started moving some samples to the ares-ide, some of then works fine others get messed by ares.

As an exercise to see how hard/easy would be to make a modification of bindings to work with arrays instead of objects, I dig in the code and by name it seems that the place to make it is at Bindings.js but I could not find how to make it accepts this notation:
bindings: [
	{from: ".model.[1]", to: ".$.firstName.content"},
	{from: ".model.[2]", to: ".$.lastName.content"},
] 
or even better:
bindings: [
	{from: ".model[1]", to: ".$.firstName.content"},
	{from: ".model[2]", to: ".$.lastName.content"},
] 
The place I found where the "from" string is parsed at Bindings.js:resolve function, but could not see even using the debugger where is the point that the data is accessed to figure out how to change it to array access.

Have someone already done something like this or can someone help me to achieve this ?

Thanks in advance for your time and great work !

Comments

  • At the moment, bindings only work with Enyo objects derived from enyo.Object... a native array isn't an object so it doesn't participate. For example, you also can't bind to a field of a plain old object. Each level of the binding needs to be something that handles the get() and set() calls.

    I could see a notation like from: ".model.1" working.

    You might have more luck using the parse method of the model to adapt your raw data format as it's being pulled into the model.

    There is support through collections for working on sets of items, but that's for repeating a binding multiple times.

    ares-ide is still a work in progress... it's mostly been designed for Enyo 2.2 apps, and the code analyzer hasn't quite caught up with all the 2.3 features.
  • I'm looking again on the "basic list" sample and I could see it has a simple way to fill the rows with data on a row by row basis and it will be easy to use data from array with it.

    Thanks for your help and time !
  • Look at the enyo core samples for DataRepeater and DataList for some guidance. We'll be focusing on more documentation shortly after we get the RC2 release ready.
Sign In or Register to comment.