javascript - ember,为什么我需要用它包装追加才能工作?

标签 javascript function append ember.js handlebars.js

我是 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/

相关文章:

python - 将变量 append 到列表时,为什么会出现“"' str' object is not callable”?

javascript - 根据文本字符串的第一个字符生成链接

javascript - 使用另一个文件的属性调用 JS 函数

c# - 删除标题时将相同的 CSV append 在一起

function - 有什么办法可以 "visualize"thunk/function?或者如何查看一般参数的函数

C 调用 ASM (YASM x86)

java - 如何暂停/恢复使用 mediarecorder 创建的录音?

javascript - 如何在 Javascript 中增加方括号内的数字

JavaScript:将对象数组转换为泛型中的 HashMap

javascript - 设置表单数据而不创建 DOM 输入