我是 ember 的初学者,我的问题很简单,我想在我的 html 中 append 一个 Handlebars ,简单,但 append (在我所有的实验中)仅当我用 $(function(){...} 包装它时才有效)。我不想使用它(如果可能的话......)。有什么替代方案、解决方案、建议吗?
<!--handlebar-->
<script type="text/x-handlebars" data-template-name="text">
<h1>Send the message:</h1>
<input {{action "clicked" on="click"}} {{bindAttr name="name_attribute"}} value='click me!!' type="button"/>
</script>
<script>
//namespace
App = Ember.Application.create();
//define view
App.myview = Ember.View.extend({
templateName: 'text',
name_attribute:'name_buttooooon',
message: '',
clicked: function(event) {
jQuery('#templateHere').html((this.get('name_attribute')));
}
});
//create view
App.myview=App.myview.create();
//insert view in body
$(function() {
App.myview.append('#templateHere'); //Why I need to wrap this line in $(function(){..})???
});
</script>
<div id="templateHere"></div>
</body>
最佳答案
应用加载后,使用 Ember.Application.ready
执行操作:
App = Ember.Application.create(
ready: function() {
this.myview.append('#templateHere');
}
);
关于javascript - ember,为什么我需要用它包装追加才能工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12765499/