gpt4 book ai didi

javascript - Ember.js ArrayController 错误

转载 作者:行者123 更新时间:2023-11-28 01:33:31 25 4
gpt4 key购买 nike

我正在尝试测试以下示例 Ember.js 代码,但 Chrome 浏览器控制台中总是显示以下错误:

Uncaught TypeError: Property '_super' of object [object Object] is not a function

代码:

MovieTracker.moviesController = Ember.ArrayController.create({
content: [],
init: function(){
this._super();
var list = [
MovieTracker.Movie.create({
title: 'Movie 1',
rating: 4 }),
MovieTracker.Movie.create({
title: 'Movie 2',
rating: 5
})];
this.set('content', list);
}
});

我正在使用 Ember-1.3.2.js

有人可以告诉我我在这里缺少什么吗?以及如何解决这个错误?

按照@kingpin2k的建议将.create更改为.extend后出现新错误消息

TypeError: Object function () { if (!wasApplied) { Class.proto(); // prepare prototype... } o_defineProperty(this, GUID_KEY, undefinedDescriptor); o_defineProperty(this, '_super', undefinedDescriptor); var m = meta(this), proto = m.proto; m.proto = this; if (initMixins) { // capture locally so we can clear the closed over variable var mixins = initMixins; initMixins = null; this.reopen.apply(this, mixins); } if (initProperties) { // capture locally so we can clear the closed over variable var props = initProperties; initProperties = null; var concatenatedProperties = this.concatenatedProperties; for (var i = 0, l = props.length; i < l; i++) { var properties = props[i]; Ember.assert("Ember.Object.create no longer supports mixing in other definitions, use createWithMixins instead.", !(properties instanceof Ember.Mixin)); if (typeof properties !== 'object' && properties !== undefined) { throw new Ember.Error("Ember.Object.create only accepts objects."); } if (!properties) { continue; } var keyNames = Ember.keys(properties); for (var j = 0, ll = keyNames.length; j < ll; j++) { var keyName = keyNames[j]; if (!properties.hasOwnProperty(keyName)) { continue; } var value = properties[keyName], IS_BINDING = Ember.IS_BINDING; if (IS_BINDING.test(keyName)) { var bindings = m.bindings; if (!bindings) { bindings = m.bindings = {}; } else if (!m.hasOwnProperty('bindings')) { bindings = m.bindings = o_create(m.bindings); } bindings[keyName] = value; } var desc = m.descs[keyName]; Ember.assert("Ember.Object.create no longer supports defining computed properties.", !(value instanceof Ember.ComputedProperty)); Ember.assert("Ember.Object.create no longer supports defining methods that call _super.", !(typeof value === 'function' && value.toString().indexOf('._super') !== -1)); Ember.assert("actions must be provided at extend time, not at create " + "time, when Ember.ActionHandler is used (i.e. views, " + "controllers & routes).", !((keyName === 'actions') && Ember.ActionHandler.detect(this))); if (concatenatedProperties && indexOf(concatenatedProperties, keyName) >= 0) { var baseValue = this[keyName]; if (baseValue) { if ('function' === typeof baseValue.concat) { value = baseValue.concat(value); } else { value = Ember.makeArray(baseValue).concat(value); } } else { value = Ember.makeArray(value); } } if (desc) { desc.set(this, keyName, value); } else { if (typeof this.setUnknownProperty === 'function' && !(keyName in this)) { this.setUnknownProperty(keyName, value); } else if (MANDATORY_SETTER) { Ember.defineProperty(this, keyName, null, value); // setup mandatory setter } else { this[keyName] = value; } } } } } finishPartial(this, m); this.init.apply(this, arguments); m.proto = proto; finishChains(this); sendEvent(this, "init"); } has no method 'get'

最佳答案

我遇到了同样的问题,因为我也在关注同一本书,终于弄清楚为什么这在 Ember 1.5.1 上不起作用:

  1. 应使用大写字母表示 MoviesController,而不是如上所述的 movieController。
  2. 应该扩展 Ember.ArrayController,而不是创建它。
  3. 不要使用 this._super()

所以下面的代码应该适合任何感兴趣的人......

MovieTracker.MoviesController = Ember.ArrayController.extend({
content: [],
init: function() {
var list = [
MovieTracker.Movie.create({
title: 'Movie 1',
rating: 4
}),
MovieTracker.Movie.create({
title: 'Movie 2',
rating: 5
})];

this.set('content', list);
}});

关于javascript - Ember.js ArrayController 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21804459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com