ember.js面临一个奇怪的问题,即当我在脚本标签中添加“data-template-name”属性时,没有任何工作。如果删除了data-template-name名称,那么一切正常。
This is NOT WORKING
<script data-template-name="my-template" type="text/x-handlebars">
Input:
{{#view App.MyView}}
{{view Ember.TextField
valueBinding="view.theValue"
placeholder="input ..." }}
{{/view}}
</script>
Now if **data-template-name="my-template"** is removed it works fine.
I mean, In UI TextField is visible.
<script type="text/x-handlebars">
Input:
{{#view App.MyView}}
{{view Ember.TextField
valueBinding="view.theValue"
placeholder="input ..." }}
{{/view}}
</script>
App.MyView = Ember.View.extend({
templateName: 'my-template',
theValue: null,
init: function(){
this._super();
this.set('theValue','asdf');
},
keyDown: function(e){
if(e.keyCode === 13){
alert(this.get('theValue'));
}
}
});
答案 0 :(得分:3)
好的,不要担心jsfiddle,这是一个好的开始:)。在ember.js网站上有一个链接,您可以在其中找到一个起点,包括Ember.js相关来源:http://emberjs.com/community/
有人说,在创建这样的Ember.js应用程序时,会有一个隐式的默认匿名模板,您可以定义自己的模板。
<!-- default template, introducing the view App.MyView -->
<script type="text/x-handlebars">
{{view App.MyView}}
</script>
<!-- template of App.View -->
<script data-template-name="my-template" type="text/x-handlebars">
Input:
{{view Ember.TextField
valueBinding="view.theValue"
placeholder="input ..."}}
</script>
javacript:
App.MyView = Ember.View.extend({
templateName: 'my-template',
theValue: null,
init: function(){
this._super();
this.set('theValue','asdf');
}
});
以下是您的示例的一个工作示例: