0

I have an object, that describes an application and one property can have several values from a list. I am using JSRender and JSViews for the databinding, I'm getting pretty good with the rendering part and I still have a lot to learn on JSViews.

I have several dropdowns in my application where the correct value is selected but I don't see how I can databind with several values inside a list box.

I created a JSFiddle to demonstrate the concept but again, I have a problem, my fiddle seems to work only when I am logged in, I gave it a name, I can see it in my public fiddles but, when connected as a Guest, I can see the code but it doesn't seem to run.

Here it is: [http://jsfiddle.net/ClaudeVernier/73pyx/]

If you could help me getting this work where the listbox is in the Red rectangle with IDs 100 and 200 selected, that would help me a lot, next, if anyone could suggest a way to have the same thing but we checboxes next to each item in the list box, it would be perfect !!!!

I think it exists as a JQuery plugin but I am not sure, if anyone has experience of such plugin and making it work with JSViews... it would be a dream... :-)

Thanks for any help, Claude

ClaudeVernier
  • 427
  • 4
  • 20

1 Answers1

0

In your jsfiddle, you are using render(), not link() so in effect you are using just JsRender, not JsViews, and you won't get JsViews data-binding.

Did you see this sample: http://www.jsviews.com/#samples/tag-controls/multiselect? It shows a multiselect listbox using JsViews.

BorisMoore
  • 8,444
  • 1
  • 16
  • 27
  • Thanks a lot ! This is great !!! Sorry I didn't find it myself as I should have... :-D – ClaudeVernier Nov 17 '13 at 20:27
  • Hello, I updated my JsFiddle: http://jsfiddle.net/ClaudeVernier/5NLGy/#base As it is, my sample doesn't work as I am using foreign keys in the selected items but when uncommenting the part where I use references to the complete list, it does work. I started to think of a solution where I convert my array of foreign key Ids to an array of the actual objects but I don't know yet if this design will work on the long term with data binding and was wondering if you had any idea for a solution on scenario like mine ? Thank you for your help, Claude – ClaudeVernier Nov 18 '13 at 11:02
  • In JavaScript an array of selected objects, consisting of references to a subset of another array will in fact contain the same objects. There is no concept of pointers as distinct from references to actual objects. And of course there is no concept of foreign keys, or even of keys at all; The script doesn't treat an ID property any differently than any other property or field on an object. So if you want your selected items to be an observable array, then to initialize that array you have to populate it appropriately through code. Multiselect will then add and remove items from that array. – BorisMoore Nov 19 '13 at 14:59