gpt4 book ai didi

ember.js - this.get 在 Controller 中是 'not a function'

转载 作者:行者123 更新时间:2023-12-05 03:10:01 31 4
gpt4 key购买 nike

我正在尝试设置 html 元素的样式,我读到我必须这样做:

bid: {
popUpContainerDisplay: "none",
popUpDisplay: Ember.computed('bid.popUpContainerDisplay', function() {
return Ember.String.htmlSafe("display: " + this.get('bid.popUpContainerDisplay'));
})
},

然后在我的 hbs 文件中,我写

<div id="popUpContainer" style={{bid.popUpDisplay}}>

但是,这给了我一些错误:

jQuery.Deferred exception: this.get is not a function TypeError: this.get is not a function
at Object.<anonymous> (http://localhost:4200/assets/auction-ember.js:53:77)
at ComputedPropertyPrototype.get (http://localhost:4200/assets/vendor.js:26852:28)
at Object.get (http://localhost:4200/assets/vendor.js:31759:19)
at NestedPropertyReference.compute (http://localhost:4200/assets/vendor.js:24910:28)
at NestedPropertyReference.value (http://localhost:4200/assets/vendor.js:24720:45)
at ReferenceCache.initialize (http://localhost:4200/assets/vendor.js:55111:52)
at ReferenceCache.peek (http://localhost:4200/assets/vendor.js:55085:29)
at DynamicAttribute.flush (http://localhost:4200/assets/vendor.js:58752:35)
at SimpleElementOperations.addAttribute (http://localhost:4200/assets/vendor.js:58414:36)
at SimpleElementOperations.addDynamicAttribute (http://localhost:4200/assets/vendor.js:58374:22) undefinedjQuery.Deferred.exceptionHook @ jquery.js:3846process @ jquery.js:3642

jquery.js:3855Uncaught TypeError: this.get is not a function(…)

我做错了什么?谢谢。

最佳答案

get 方法在您尝试使用它的对象中不存在。

get 方法来自 Ember.Observable , 由 Ember.Object 使用类(class)。您需要做的是使用 extend 或 create 将 bid 属性声明为 Ember.Object,如下所示:

bid: Ember.Object.extend({
popUpContainerDisplay: "none",
popUpDisplay: Ember.computed('bid.popUpContainerDisplay', function() {
return Ember.String.htmlSafe("display: " + this.get('bid.popUpContainerDisplay'));
})
})

关于ember.js - this.get 在 Controller 中是 'not a function',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41338814/

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