我有一个textarea绑定到div,这样你在textarea中输入的任何内容都会更新div.
绑定不受尊重的唯一事情是textarea中的换行符,所以如果你在textarea中点击'enter',那么div就不会中断.
小提琴:http://jsfiddle.net/lifeinafolder/Ajkyw/19/
我正在使用帮助器,但它不起作用.
根据此链接上的第4点:http://codebrief.com/2012/03/eight-ember-dot-js-gotchas-with-workarounds/,它不应该工作.但即使有关于该链接的解决方案,我也无法让它发挥作用.
有关如何使用<br/>textarea中的换行符上的标签更新div的任何想法?
使用计算属性来格式化位置的换行符.
HTML:
<script type="text/x-handlebars">
{{#with App.obj}}
{{view Ember.TextArea valueBinding="location"}}
<div>{{{formattedLocation}}}</div>
{{/with}}
</script>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
App.obj = Ember.Object.create({
location:'Palo Alto',
formattedLocation: function() {
return this.get('location').replace(/\n\r?/g, '<br />');
}.property('location').cacheable()
});
Run Code Online (Sandbox Code Playgroud)
在示例中,我删除了您的帮助程序,以便更准确地了解正在发生的事情.如果您需要使用帮助程序并且无法弄清楚,请告诉我,我将重新添加帮助程序.