ember.js - ember 未捕获错误 : assertion failed: Emptying a view in the inBuffer state

标签 ember.js ember-data ember-old-router

运行下面的代码时我得到这个断言:

Emptying a view in the inBuffer state is not allowed and should not happen under normal circumstances. Most likely there is a bug in your application. This may be due to excessive property change notifications.

演示链接: http://plnkr.co/edit/s3bUw4JFrJvsL690QUMi

var App = Ember.Application.create({
  Store: DS.Store.extend({
    revision: 4,
    adapter: DS.FixtureAdapter.create()
  }),

  Router: Ember.Router.extend({
    root: Ember.Route.extend({
      index: Ember.Route.extend({
        route: "/",
        connectOutlets: function(router){
          var person;
          person = App.Person.find(657);
          person.addObserver("isLoaded", function() {
            return router.get('router.applicationController').connectOutlet("things", person.get("things"));
          });
        }
      })
    })
  }),

  ApplicationController: Em.Controller.extend(),

  ApplicationView: Em.View.extend({
    template: Em.Handlebars.compile("{{outlet}}")
  }),

  ThingsController: Em.ArrayController.extend({
    thingTypes: (function() {
      return App.ThingType.find();
    }).property()
  }),

  ThingsView: Em.View.extend({
    template: Em.Handlebars.compile([
      '{{#each controller.thingTypes}}', 
        '{{this.name}}', 
      '{{/each}}',
      '{{#each controller.content}}', 
        '{{this.title}}', 
      '{{/each}}'].join(""))
  }),

  //MODELS
  Person: DS.Model.extend({
    things: DS.hasMany('App.Thing', {
      embedded: true
    })
  }),

  Thing: DS.Model.extend({
    description: DS.attr('string'),
    thingType: DS.belongsTo("App.ThingType", {
      embedded: true
    }),
    title: (function() {
      return this.get("thingType.name");
    }).property("description")
  }),

  ThingType: DS.Model.extend({
    name: DS.attr("string")
  })
});

App.Person.FIXTURES = [
  {
    id: 657,
    things: [
      {
        id: 1,
        description: "Some text",
        thing_type: {
          id: 1,
          name: "type 1"
        }
      }, {
        id: 2,
        description: "Some text",
        thing_type: {
          id: 2,
          name: "type 2"
        }
      }
    ]
  }
];

App.ThingType.FIXTURES = [
  {
    id: 1,
    name: "type 1"
  }, {
    id: 2,
    name: "type 2"
  }, {
    id: 3,
    name: "type 3"
  }
];

为什么会发生这种情况?

最佳答案

我在尝试从灯具加载下拉值列表时遇到了同样的错误。解决这个问题的方法是重写夹具适配器上的queryFixtures:

App.FixtureAdapter = DS.FixtureAdapter.extend
  latency: 200
  queryFixtures: (records, query, type) ->
    records.filter (record) ->
      for key of query
        continue  unless query.hasOwnProperty(key)
        value = query[key]
        return false  if record[key] isnt value
      true

如果我没有先设置延迟,我可能不会弄清楚这一点。然后错误更具描述性。

关于ember.js - ember 未捕获错误 : assertion failed: Emptying a view in the inBuffer state,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14379979/

相关文章:

ember.js - Emberjs 开发一个与其自己的路由/状态隔离的组件,可以将其集成到主应用程序中

ruby-on-rails - 使用 Rails 的 EmberJS 路由

html - Ember.js 身份验证、推送状态和路由

ember.js - 如何返回延迟 promise 并使用 Ember.Deferred 创建模型?

Ember.js View 和参数

javascript - Ajax Get 方法不使用 Ember Js 返回值

javascript - EmberJS - 断言失败 : The value that #each loops over must be an Array. 你通过了(生成的应用程序 Controller )

ember.js - 使用 store.createRecord 手动创建新记录时如何应用自定义转换

javascript - 在 Controller emberjs 中获取模型

javascript - Ember-Data: "mappings"是如何工作的