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

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 に答える