2016-12-27 58 views
1

我想设置一个HTML元素的风格,我阅读,我必须这样做,这样说:this.get在控制器是“不”的函数

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(…) 

我在做什么错?谢谢。

回答

1

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

get方法来自Ember.Observable,这是由Ember.Object类使用。你所要做的就是声明bid属性作为Ember.Object,使用扩展或创建,像这样:

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

我遇到了一个服务的问题,它已经有'Ember.Service.extend()' –

0

你需要把计算的地产出bid

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