17

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

清空处于 inBuffer 状态的视图是不允许的,在正常情况下也不应该发生。您的应用程序中很可能存在错误。这可能是由于过多的属性更改通知。

演示链接: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"
  }
];

为什么会这样?

4

2 回答 2

2

我在尝试从固定装置加载下拉值列表时遇到了同样的错误。解决它的是覆盖夹具适配器上的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

如果我没有先设置延迟,我可能不会想出来。然后错误更具描述性。

于 2014-02-26T15:26:19.297 回答
0

我想有点晚了......但我让它在这里工作:http: //plnkr.co/edit/hDCT4Qy1h5aE6GjM76qp

没有改变逻辑,但它被称为

我这样修改了你的路由器:

Router: Ember.Router.extend({
    root: Ember.Route.extend({
      index: Ember.Route.extend({
        route: "/",
        connectOutlets: function(router) {
          var person;
          router.set('router.applicationController.currentPerson', App.Person.find(657));
        }
      })
    })
  })

并创建了一个ApplicationController:

ApplicationController: Em.Controller.extend({
    currentPerson: null,
    currentPersonLoaded: function() {
      this.connectOutlet("things", this.get("currentPerson.things"));
    }.observes("currentPerson.isLoaded"),
  })

我不知道这是否是您想要的输出,但错误消失了!

于 2013-12-14T01:20:45.947 回答