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

前端 未结 11 1902
独厮守ぢ
独厮守ぢ 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:33

    Actually you want to find whether the event is triggered by user or program , and its obvious that event will trigger while initialization.

    The knockout approach of adding subscription won't help in all cases, why because in most of the model will be implemented like this

    1. init the model with undefined data , just structure (actual KO initilization)
    2. update the model with initial data (logical init like load JSON , get data etc)
    3. User interaction and updates

    The actual step that we want to capture is changes in 3, but in second step subscription will get call , So a better way is to add to event change like

     
                            
        
    提交评论

提交回复
热议问题