lip*_*ipp 2 binding textarea helper ember.js
我有一个Ember.Handlerbars.JSON帮助器,它将给定值格式化为缩进的JSON字符串.我想设置textarea的内容(值),如下所示:
{{#view Ember.TextArea}}
{{JSON someValue}}
{{/view}}
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为我应该设置textareas的"值"属性.
但是,这也不起作用
{{view Ember.TextArea valueBinding="JSON someValue"}}
Run Code Online (Sandbox Code Playgroud)
您可以使用计算属性来解决此问题,请参阅http://jsfiddle.net/pangratz666/3A33H/:
把手:
<script type="text/x-handlebars" >
{{#with App.jsonController}}
{{view Ember.TextArea valueBinding="formatted" rows="10" }}
{{/with}}
</script>?
Run Code Online (Sandbox Code Playgroud)
JavaScript:
App = Ember.Application.create({
formatJSON: function(obj) {
return JSON.stringify(obj, null, '\t');
}
});
App.jsonController = Ember.Object.create({
content: {
abc: 123,
foo: 'hello'
},
formatted: function() {
var obj = this.get('content');
return App.formatJSON(obj);
}.property('content')
});?
Run Code Online (Sandbox Code Playgroud)
更新您的评论:
在评论中的小提琴(http://jsfiddle.net/4QNur/)你声明{{view Ember.TextArea valueBinding="JSON App.someComplexValue"}}:这不起作用,因为valueBinding将路径作为参数而不是表达式,如JSON App.someComplexValue.如果要绑定到转换后的值,只需创建一个计算属性并绑定到它.那是Ember做这种事的方式......
在原始问题中,您有以下代码:
{{#view Ember.TextArea}}
{{JSON someValue}}
{{/view}}
Run Code Online (Sandbox Code Playgroud)
这并不在这种情况下工作,因为value对于Ember.TextArea只能通过设置value分别为valueBinding:
{{view Ember.TextArea valueBinding="App.controller.transformedComplexValue" }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3068 次 |
| 最近记录: |