Ember not updating the view on model change

萝らか妹 提交于 2019-12-23 11:50:03

问题


This fiddle has the starter kit recreated, with and extra button that alters the model.

http://jsfiddle.net/UjacC/1/

However, when clicking change, the array changes, but the view is not being updated. Why?

<title>Ember Starter Kit</title>

<body>

  <script type="text/x-handlebars">
    <h2>Welcome to Ember.js</h2>
        <button id="btnChange">change model</button>
    {{outlet}}
  </script>

  <script type="text/x-handlebars" data-template-name="index">
    <ul>
    {{#each item in model}}
      <li>{{item}}</li>
    {{/each}}
    </ul>
  </script>

  <script>
         $(document).ready(function(){
          console.log(stuff);

          $("#btnChange").click(function(){
            stuff.push("d");
            console.log("change",stuff);
          });

      });
    </script>

</body>




App = Ember.Application.create();

var stuff = ["a","7","b","c"];

App.Router.map(function() {
  // put your routes here
});

App.IndexRoute = Ember.Route.extend({
  model: function() {
    return stuff;
  }
});

回答1:


Instead of stuff.push you need to use Embers pushObject which will notify listeners of an object that there was a change to it.

EDIT:

Here's the updated jsfiddle: http://jsfiddle.net/UjacC/2/



来源:https://stackoverflow.com/questions/18793522/ember-not-updating-the-view-on-model-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!