KnockoutJS subscribe to property changes with Mapping Plugin

前端 未结 2 1889
青春惊慌失措
青春惊慌失措 2021-02-01 17:16

Is there anyway I can tell the knockout mapping plugin to subscribe to all property changes call a certain function?

I realize I can manually subscribe to the property c

2条回答
  •  眼角桃花
    2021-02-01 18:15

    This handy little plugin is pretty close to what you did but it comes with several options and can work over a much broader set of requirements without requiring the Mapping plugin:

    https://github.com/ZiadJ/knockoutjs-reactor

    Basically it allows you to write this kind of code:

    ko.watch(viewModel, function(target, trigger) { 
        // do work
    });  
    

提交回复
热议问题