我在访问组件内的输入值时遇到问题。我试图在我的模板中动态创建值绑定,并使用this.controller.get(“pst”+ id)访问conponent.js文件,但结果不明确。使用Ember 2.2访问ember中的动态输入值#each块中的ember
{{#each post in |pst idx|}}
{{input value=(concat 'pst' idx)}}
{{/each}}
我在访问组件内的输入值时遇到问题。我试图在我的模板中动态创建值绑定,并使用this.controller.get(“pst”+ id)访问conponent.js文件,但结果不明确。使用Ember 2.2访问ember中的动态输入值#each块中的ember
{{#each post in |pst idx|}}
{{input value=(concat 'pst' idx)}}
{{/each}}
那么,it works as expected,但你为什么要这样做呢?
请解释你想要存档的内容,然后我们可以帮助更好。
而且很明显,使用get
助手生成的值是不可变的。
为什么不做点像{{input value=pst}}
? 如果这不是一个选项,可能应该在JS中构建数组,然后在句柄中使用它!
定义在您的component.js文件中封装“post”变量的计算属性。迭代该包装。我认为这是产生动态价值的有力方式。
您的模板:
{{#each postWrappers as postWrapper}}
{{input value=postWrapper.value}}
{{/each}}
你component.js:
postWrappers : Ember.computed('post', function() {
//your concat code
});
灰烬版本?尝试'{{#each post as | pst idx |}}' – AcidBurn
这似乎是与创建值绑定到的变量的问题。 concat帮助器函数建立一个字符串,但是当我在动态创建的字符串上尝试this.get.controller(“..”)时,它不会返回输入框的值(并返回undefined) – goofiw
我相信你需要的是'get' helper,可能与concat:'(get this(concat“pst”idx))''一起使用。 – locks