0

我正在尝试将 Ember-Brunch(原始存储库:https ://github.com/icholy/ember-brunch )更新为最新的 EmberJS 和 EmberJS-Data 框架。我目前遇到的问题是我正在尝试将原始 Bob 模型转换DS.ModelDS.FixtureAdapterDS.Store. 但无论我尝试什么,我都会遇到让数据显示的问题。这里有几个尝试:

随着路线:

App.BobRoute = Ember.Route.extend({
    model: function() { 
        return App.Bob.find();
    }
});

我收到以下错误:

未捕获的 TypeError:无法调用 null 的方法“hasOwnProperty”

如果我切换到这条路线:

App.BobRoute = Ember.Route.extend({
    setupController: function() {
        App.BobController.set('content', App.Bob.find());
      }
});

我收到以下错误:

未捕获的类型错误:对象 App.BobController 没有方法“设置”app.js:184 未捕获的类型错误:无法调用 null 的方法“hasOwnProperty”

有任何想法吗?

您可以查看我当前的工作https://github.com/seankeating/ember-brunch以及我在 DS.Model-Implementation-For-Using-Local-DSStore 分支中的尝试。

店铺:

App.Store = DS.Store.extend({
  revision: 11,
  adapter: DS.FixtureAdapter.create()
});

控制器:

App.BobController = Em.ObjectController.extend({

});

模型:

var App = require('app'),
    attr = DS.attr;

App.Bob = DS.Model.extend({

    firstName : attr('string'),
    lastName  : attr('string'),
    lyrics    : attr('string'),

    fullName: function(){
        return this.get('firstName') + ' ' + this.get('lastName');
    }.property('firstName', 'lastName')

});

App.Bob.FIXTURES = [{
    firstName: 'bob',
    lastName: 'marley',
    lyrics: 'no woman no cry!'
}];

模板:

<h2>{{fullName}}'s page!</h2>
<button class="btn btn-success" {{action doClick target="view"}}>click me</button>
{{#linkTo home}}<button class="btn" {{action doHome}}>go back home</button>{{/linkTo}}
4

1 回答 1

2

bc755f9之前,您需要将夹具键作为字符串提供,这就是 Ember Data 在内部存储它们的方式。

现在,您可以使用数字或字符串作为灯具 ID,一切都会按预期工作。

另外,您应该始终在开发中使用 Ember.js 的调试版本,如果出现问题,它会提供更好的错误消息。从ea6922f 开始,如果您在localhost127.0.0.1.

于 2013-01-13T05:09:37.777 回答