2014-10-02 55 views
0

首先感謝RivetJS,我用它來流動,太棒了!如何在rivetjs中更新模型onkeyup

問題:在AngularJS中通常會在輸入中獲取綁定以更新模型onkeyup。在RivetJS中,默認似乎正在更新模型onblur。有沒有辦法讓每個onkeyup事件更新模型?

謝謝

回答

1

您有2個選項。首先,升級到Rivets 0.7 - 如the changelog所述:「內置值綁定器現在監聽輸入事件而不是更改,因此更新將立即傳播,而不是模糊。」要注意的重大更改,並相應地升級你的實現(例如,你要麼需要鉚釘之前,包括Sightglass或使用the bundled rivets.js file

另一種選擇,如果你想留在鉚釘0.6,是創建自己的粘合劑。作爲作者自己gives an example我只會用到:

rivets.binders.input = { 
    publishes: true, 
    routine: rivets.binders.value.routine, 
    bind: function(el) { 
    el.addEventListener('input', this.publish) 
    }, 
    unbind: function(el) { 
    el.removeEventListener('input', this.publish) 
    } 
}