Change event on select with knockout binding, how can I know if it is a real change?

前端 未结 11 2100
独厮守ぢ
独厮守ぢ 2021-01-30 08:05

I am building a permissions UI, I have a list of permissions with a select list next to each permission. The permissions are represented by an observable array of objects which

11条回答
  •  忘了有多久
    2021-01-30 08:49

    This is just a guess, but I think it's happening because level is a number. In that case, the value binding will trigger a change event to update level with the string value. You can fix this, therefore, by making sure level is a string to start with.

    Additionally, the more "Knockout" way of doing this is to not use event handlers, but to use observables and subscriptions. Make level an observable and then add a subscription to it, which will get run whenever level changes.

提交回复
热议问题