datatable+angularjs-在单击属性时传递数据属性

qncylg1j  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(214)

不知道如何很好地打包这个问题,但我已经将angularjs与datatables集成在一起了。我想知道,当我在datatable的render()函数中使用数据属性时,如何在单击属性上传递数据属性

render: function(d, t, r, m) {
  let actions = '';
  data.actions.forEach(a => {
    actions += `<button ng-click="${a.click(r)}">${a.label}</button>`;
  });
  return actions;
}

(请参考下面的代码)
以下是守则的重要部分:

// DIRECTIVE
mod.directive('libTable', function() {
  return {
    controller: 'Controller',
    link: function(scope, element, attrs, Controller) {
      scope.$watch('data', function() {
        Controller.setup(scope.data);
      });
    }
  };
});

// CONTROLLER
mod.controller('Controller', function ($scope) {
  this.setup = (data) => {
    // some other codes here...
    $scope.dtColumns.push({
    data: 'Actions',
    title: 'Actions',
    render: function(d, t, r, m) {
      let actions = '';
      data.actions.forEach(a => {
        actions += `<button ng-click="${a.click(r)}">${a.label}</button>`;
      });
      return actions;
    }
  });
});

这个函数可以工作,但是它会在页面加载时立即执行,我不希望发生这种情况,因为我只希望在单击按钮时触发它。
非常感谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题