JQuery KO 按钮在 mRender 函数中不起作用


{
  sTitle: '', mData: 'id', bSearchable: 'false', bSortable: false, sWidth: '290px',
  mRender: function (data, type, full) {
    return "<button type='button' class='btn btn-primary' onclick =" + self.startResetPassword(full) + "></button>"
    //return "<button type='button' id='ResetPassword' class='btn btn-primary' data-bind='click:{return self.startResetPassword("+full.id+");}'></button>"
    //return "<button type='button' class='btn btn-primary btn-xs' data-bind='click: " + function () { return self.startResetPassword("+full.id+"); } + "'></button>"
  }
}

上述按钮功能均不起作用

像这样放置点击处理程序并不受欢迎,我建议像这样添加它:

mRender: function (data, type, full) {
    return "<button type='button' class='btn btn-primary' data-button-id="+full.id+"></button>"
}
...
contentElement.on('click', 'button.btn-primary', function(){
   var elementData = $(this).data('button-id');
   self.startResetPassword(elementData )
});

最新更新