xeditable onbeforesave 不触发

xeditable onbeforesave not firing

我在使用 xeditable 指令时遇到问题。 onbeforesave 没有触发,即使就地编辑在客户端运行良好。我无法从 onbeforesave 或 onaftersave 得到任何反应。

我在我的项目中包含了 angular 版本 1.5.0。 我正在这样设置元素,它位于 table:

<tr ng-repeat="job in jobs">
  <td>{{ job._id }}<i ng-click="removeJob(job._id)" class="fa fa-trash-o" aria-hidden="true"></i></td>
  <td>{{ job.title }}</td>
  <td editable-text="job.description" onbeforesave="alert('hello');">{{ job.description || "empty" }}</td>
</tr>

但是我无法在单击“保存”时关闭警报。

如果你看the documentation

One way to submit data on server is to define onbeforesave attribute pointing to some method of scope

onbeforesave 接受范围方法,因此 alert('hello') 在这种情况下试图调用一些 $scope.alert 不存在的方法。要完成这项工作,请尝试类似

// in your controller

$scope.test = function(data) {
    alert(data);
};

// in your template

<tr ng-repeat="job in jobs">
  <td>{{ job._id }}<i ng-click="removeJob(job._id)" class="fa fa-trash-o" aria-hidden="true"></i></td>
  <td>{{ job.title }}</td>
  <td editable-text="job.description" onbeforesave="test($data)">{{ job.description || "empty" }}</td>
</tr>

你必须给 e-form 如下所示(我只是提取了错误的代码片段而已)。

Html

<td editable-text="job.description" e-form="tableform" 
onbeforesave="checkJob(job)">{{ job.description || "empty" }}</td>

JS

 $scope.checkJob= function(data) {

   //your logic

  };