Knockout.js - javascript function on data-bind

后端 未结 5 1476
天命终不由人
天命终不由人 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

    Well I am just going through the tutorial myself but I thought you had to set up a property and use ko.computed to give it its value (from the tutorial):

    function AppViewModel() {
    this.firstName = ko.observable("Bert");
    this.lastName = ko.observable("Bertington");
    this.fullName = ko.computed(function(){ 
      return this.firstName() + " " + this.lastName(); 
      },this);
    }
    

    Then you can have:

    Full name: 
    

提交回复
热议问题