繁体   English   中英

模型更新后,Ember模板不更新

[英]Ember template doesn't update after model update

http://jsbin.com/qoyudape/1/edit

尽管使用.pushObject()模板不会更新。 我发现它不更新,如果不是this我用modelcontent的模板;

什么是this鉴于指的是如果没有模型? 是否可以使用this而不是modelcontent使其工作?

var App = Ember.Application.create();

App.ApplicationRoute = Ember.Route.extend({
  model: function(){
    return Ember.A();
  }
});

App.ApplicationController = Ember.ArrayController.extend({
  actions: {
    update: function(){
      this.get("model").pushObject( Ember.Object.create({a:"b"}) );
      console.log( this.get("model") );
    }
  }
});

模板:

<script type="text/x-handlebars">

    <button {{action "update"}}>update</button>
    <br><br>

    {{#if this}}
      array not empty
    {{else}}
      array empty
    {{/if}}
  </script>

this是指控制器。 顺便说一句,一种简单的发现方法是在模板中进行{{log this}} ,另请参见: http : //emberjs.com/guides/understanding-ember/debugging/

我实际上不确定要检查的内容是否真实/虚假,但是您始终可以使用长度。 找到后,我会更新。

{{#if this.length}}
  array not empty
{{else}}
  array empty
{{/if}}

http://jsbin.com/qoyudape/3/edit

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM