【发布时间】:2015-06-12 11:53:58
【问题描述】:
我有一个模型,其中包含有关选择、输入等信息。我找到了将它连接到我的视图的方法。
export default Em.View.extend({
didInsertElement: function(){
var content = this.get('content'),
self = this;
content.content[0].default.forEach(function(item,i){
if (item.tag == 'select') {
self.$().append('<select></select>');
item.content.forEach(function(item){
self.$('select:last-child').append('<option>'+item.option+'</option>');
});
}
else if (item.tag == 'input') {
self.$().append('<input type='+item.type+'>');
}
});
}
});
有没有办法不使用:
self.$('select:last-child').append('<option>'+item.option+'</option>');
还有一些
Ember.compile('{{Ember.select content=options valueBinding=example}}');
谢谢!
附:抱歉,如果您觉得我的做法很愚蠢,我刚开始学习 Ember,可能我仍然以 jquery 的方式思考。对不起我的英语!
【问题讨论】:
-
视图的实际用途是什么?它在表面上提供了哪些功能?是的,您的代码过度依赖 jQuery。
-
任务是从 JSON 文件构建表单,其中部分表单可以更改,只需编辑 JSON 即可删除。
-
只需在项目中添加一个
isSelect和isInput,然后使用普通的if helpers。
标签: javascript ember.js view