0
我的Riot.js observable的工作方式如下。無法獲得Riot.js可觀察到的通過回調傳遞參數
在我的「全球頭」標籤riot.store防暴全球範圍內觀察到的被更新(用戶輸入的輸入領域的一個新的高度),然後觀察的觸發器「update_dims」:
save_height() {
riot.store.cardHeight = this.refs.input_card_height.value
riot.store.trigger('update_dims')
}
在我的'卡片'標籤裏面,riot.store監聽'update_dims'併成功更新界面中的{myCardHeight}。
// function updates the card height
update_cardHeight() {
this.myCardHeight = riot.store.cardHeight
this.update()
}
// observable runs when triggered and calls above function 'update_cardHeight'
riot.store.on('update_dims',this.update_cardDimensions)
但是,如果我嘗試直接從riot.store.trigger傳遞參數:
save_height() {
riot.store.cardHeight = this.refs.input_card_height.value
riot.store.trigger('update_dims','450')
}
下觀察到的不更新,即使me.myCardHeight變量已經用新更新的界面高度參數:
me = this
riot.store.on('update_dims', function (height) {
me.myCardHeight = height
console.log(me.myCardHeight)
me.update()
})
什麼是做到這一點的正確方法?