Knockout.js - javascript function on data-bind

后端 未结 5 1478
天命终不由人
天命终不由人 2021-02-12 12:38

Is there a way i can call JavaScript function on data-bind like this:

         


        
5条回答
  •  不思量自难忘°
    2021-02-12 12:45

    You can use arbitrary JavaScript expressions for bindings, but keep in mind that they are evaluated in the viewmodel's context, so all functions in the expression have to be properties of viewmodel. In your case, MySomeFunction has to be a property of your viewmodel. If you create your viewmodel using mapping plugin, you can attach additional functions to the viewmodel like this:

    var viewModel = ko.mapping.fromJS(data.d)
    viewModel.MySomeFunction = function(...){...};
    

提交回复
热议问题