所以我想轉換成一個咖啡腳本類的淘汰賽模型,直到現在還沒有用過咖啡,在如何調用property.sub淘汰賽功能, coffeescript(和我的班級)。目前,該代碼如下所示(嚴重簡單化得到點跨越)淘汰賽模式咖啡腳本類語法轉換
var Autocomplete = function(){
var self = this;
self.displayResults = ko.observable(false);
self.results = ko.observableArray([]);
self.hasResults = ko.observable(false);
self.hasResults.subscribe(function(newValue){
if(newValue == true) {
self.displayResults(true);
} else {
self.displayResults(false);
}
});
}
但基本上什麼林試圖做的是:
class ClientAutoComplete
constructor: ->
@hasResults = ko.observable(false)
@results = ko.observableArray([])
@displayResults = ko.observable(false)
hasResults.subscribe: (newValue) ->
@displayResults(newValue)
我無法弄清楚什麼是如何調用property.subscribe方法正確,ive嘗試了幾種不同的語法,但無濟於事。任何人都可以對此有所瞭解嗎?非常感謝提前。
我實際上嘗試過,但是我得到了一個解析錯誤,意外{在第x行 - 但是,因爲你引導我在正確的方向,我能夠通過以下方式獲得它:@ hasResults.subscribe(newValue)=> @ displayResults(newValue)(注意訂閱後顯然需要不冒號) – thrice801
,謝謝你的詳細解釋! – thrice801
@ thrice801:對不起,我錯過了冒號。無論如何,我更新了答案以涵蓋那部分。 –