javascript - EmberJS Custom Textbox View with ID-suffix -
let's assume i've got ember.arraycontroller:
app.itemsarraycontroller = ember.arraycontroller.extend({ //some additional functions }).create() this array controller holds objects of:
app.item = ember.object.extend({ id: 0, //after item loaded id contains real id of item value: "some value" }) in handlebars template i've got:
{{#each item in app.itemsarraycontroller}} <input id="item" valuebinding="item.value" /> {{/each}} you can see, input generated x-times depending on number of items in controller. issue inputs have same id of "item". cannot use like:
<input id="item-{{item.id}}" valuebinding="item.value" /> because handle {{ }} wraps value ember metamorph script wrapper , handle {{{ }}} works same way.
what want custom view can use like:
{{view app.textfieldwithidsuffix id="item-" idsuffixbinding="item.id" valuebinding="item.value"}} and should rendered as:
<input type="text" id="item-0" value="some text" /> my view app.textfieldwithidsuffix defined as:
app.textfieldwithidsuffix = ember.view.extend({ tagname: "input" }); how define app.textfieldwithidsuffix view support xxxbindings attributes , when rendered id altered suffix?
try following.
on controller, add:
idformat: function(id) { return "item-" + id; } and write input tags as:
<input id={{idformat item.id}} valuebinding"item.value" />
Comments
Post a Comment