remy / bind.js

bind.js - simple two way data binding to HTML and callbacks
694 stars 62 forks source link

Bind <Select> #17

Open DCSDB opened 8 years ago

DCSDB commented 8 years ago

I am trying to bind the values of an array to the input values of a select, similar to how you bind "cats" to a UL in the playground. If I assign the array to a UL with the function :

dom:'#cats', transform: function (item){return "";}

and #cats is a UL, the the values are printed.

If I change #cats to a SELECT I get no love. any ideas?

Thank you

remy commented 8 years ago

Can you paste up the code that you're using?

DCSDB commented 8 years ago

Sure : https://jsbin.com/xinadegesa/edit?html,js,console,output

change "" to "

" and you will see the list render correctly.

Cheers.

remy commented 8 years ago

I think the transform should actually contain the following (since it receives the updated array, and doesn't fire for each element):

transform: function (cat) {
  return cat.map(_ => `<option>${_.name}</option>`);
}

But this still doesn't update, so I need to investigate a little further.

remy commented 8 years ago

Would appreciate input on this: https://github.com/remy/bind.js/issues/23

raminasri commented 8 years ago

Change this: "var valueSetters = ['SELECT', 'INPUT', 'PROGRESS', 'TEXTAREA'];" TO var valueSetters = ['OPTION', 'INPUT', 'PROGRESS', 'TEXTAREA'];