模板中的动态值 [英] dynamic value in template

查看:129
本文介绍了模板中的动态值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经扩展了一个视图(使用fieldId生成器函数)并设置了以下模板:



我需要为标签设置相同的计算IDfor属性(用view.fieldId计算)和{{view Em.Textfield ...}}



如何在{ {view Em.TextField expression ..}}?



任何其他替代方案?

  template:Ember.Handlebars.compile('< label class =control-label{{bindAttr for =view.fieldId}}> {{view.label}}< / label> \\ 
< div class =controls> \
{{查看Em.TextField valueBinding =view.valueclass =input-large}} \
< ; span class =help-inline>可能出错了< / span> \
< / div>')


解决方案

解决方案是绑定 for Emax.TextField elementId 属性的< label> $ c>。



首先,你必须通过设置它的 viewName 属性给一个名字给你的Ember.TextField :

  {{view Ember.TextField viewName =myTextField}} 
/ pre>

然后,您必须将其 elementId 绑定到 属性,使用 bindAttr

 < label { {bindAttr for =view.myTextField.elementId}}>我的标签< / label> 

它的工作原理只是尝试在这个JSFiddle



注意:另一个解决方案是嵌套输入内的标签。有关详细信息,请查看此SO问题:对标签使用Ember.js文本字段标识


I'have extended a View (with a fieldId generator function) and set the following template:

I need to have the same computed id for the label "for attribute" ( computed with view.fieldId) and the {{view Em.Textfield ...}}

How to set the id attribute with view.fieldId in the {{view Em.TextField expression..}} ?

Any other alternative ?

template: Ember.Handlebars.compile('<label class="control-label" {{bindAttr for="view.fieldId"}}>{{view.label}}</label>\
                     <div class="controls">\
                     {{view Em.TextField valueBinding="view.value" class="input-large"}}\
                     <span class="help-inline">Something may have gone wrong</span>\
                     </div>')

解决方案

The solution is to bind the for attribute of the <label> to the elementId property of the Ember.TextField.

First, you have to give a name to your Ember.TextField by settings its viewName property:

{{view Ember.TextField viewName="myTextField"}}

Then, you have to bind its elementId to the for attribute, using bindAttr:

<label {{bindAttr for="view.myTextField.elementId"}}> My label </label>

And it works, just try it in this JSFiddle.

N.B.: There is one other solution is to nest the input inside the label. For more information, take a look at this SO question: Using Ember.js text field ids for a tag

这篇关于模板中的动态值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆