我目前面临计算属性的问题,我有一个名为crossconnection的模型,其中包含一些计算属性,如:
relevantPoints: computed(function () {
if (this.get('IsCA') === true && this.get('IsCM') === true) {
return "/assets/images/big/ca-cm.png";
}
else if (this.get('IsCA') === true && this.get('IsCM') === false) {
return "/assets/images/big/ca.png";
}
else if (this.get('IsCA') === false && this.get('IsCM') === true) {
return "/assets/images/big/cm.png";
}
else if (this.get('IsCA') === false && this.get('IsCM') === false) {
return "/assets/images/big/nca-ncm.png";
}
}),
运行项目时,我不断收到以下错误:
未捕获的TypeError:无法将类作为函数调用
请有人澄清一下吗?
PS: 我正在使用,
更新:
澄清:我有一个包含一些计算属性的模型'crossconnection',我的模型是通过一个简单的
从控制器中调用的from = this.store.query('crossconnection ', {
fromOpKey: this.get('opSelected').get('opKey'),
limit: -1
});
然后导致以下错误(附加完整堆栈跟踪)
Uncaught TypeError: Cannot call a class as a function
at classCallCheck (ember-babel.js:11)
at Object.Class [as Object] (core_object.js:25)
at Module.callback (crossconnection.js:65)
at Module.exports (loader.js:106)
at requireModule (loader.js:27)
at Class._extractDefaultExport (index.js:410)
at Class.resolveOther (index.js:110)
at Class.superWrapper [as resolveOther] (ember-utils.js:420)
at Class.resolve (resolver.js:133)
at _resolve (container.js:871)
classCallCheck @ ember-babel.js:11
Class @ core_object.js:25
(anonymous) @ crossconnection.js:65
Module.exports @ loader.js:106
requireModule @ loader.js:27
_extractDefaultExport @ index.js:410
resolveOther @ index.js:110
superWrapper @ ember-utils.js:420
resolve @ resolver.js:133
_resolve @ container.js:871
resolve @ container.js:574
resolve @ container.js:578
factoryFor @ container.js:136
factoryFor @ container_proxy.js:40
modelFactoryFor @ -private.js:11593
_modelFactoryFor @ -private.js:11556
_modelFor @ -private.js:11547
modelFor @ -private.js:11540
_query @ -private.js:8666
_query @ -private.js:10819
query @ -private.js:10806
(anonymous) @ ops.js:55
applyStr @ ember-utils.js:524
sendEvent @ ember-metal.js:257
notifyObservers @ ember-metal.js:1103
propertyDidChange @ ember-metal.js:886
set @ ember-metal.js:2893
set @ observable.js:104
openOpPopupWithKey @ ops.js:143
send @ action_handler.js:28
(anonymous) @ action.js:124
exports.flaggedInstrument @ ember-metal.js:3920
(anonymous) @ action.js:123
_run @ backburner.js:758
_join @ backburner.js:736
join @ backburner.js:477
run.join @ ember-metal.js:4366
handler @ action.js:102
(anonymous) @ event_dispatcher.js:234
dispatch @ jquery.js:5183
elemData.handle @ jquery.js:4991
答案 0 :(得分:6)
请确保正确导入computed
:
import { computed } from '@ember/object';
答案 1 :(得分:1)
编辑 - 这似乎不是错误的原因,但我现在暂时将它留在这里
您在计算中缺少一个参数。 Computed首先将属性视为字符串,然后是回调函数:
relevantPoints: computed(‘isCA’, ‘isCM’, function () {
if (this.get('IsCA') === true && this.get('IsCM') === true) {
return "/assets/images/big/ca-cm.png";
}
...,
}),
这个答案适用于1.13到3.x,对<的代码片段进行了一处小修改。 3.0。小于3.0的应用程序版本应该执行Ember.computed而不是计算。