2014-01-24 28 views
11

当用户添加一个新行并单击取消按钮(不放置任何数据)时,可能会删除该行。 否则,我该如何更改取消按钮代码,因为这一个使用angularJS的默认可编辑代码(或者,如果该行为空,我怎样才能调用删除功能?)自定义X-editable(AngularJS)的取消代码按钮

这是EXAMPLE

HTML了取消键:

 <button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default"> 
     cancel 
     </button> 

回答

13

你可以调用自己的函数。要做到这一点,你应该改变你的HTML这样的:

<button type="button" ng-disabled="rowform.$waiting" 

     ng-click="cancelAdvice(rowform, $index)" 

     class="btn btn-default"> 
     cancel 
</button> 

正如你可以看到有与窗体和当前指数作为参数的新功能。在你的控制器,你必须定义这个功能:

$scope.cancelAdvice = function(rowform, index){ 
    console.log(rowform, index); 
    $scope.removeUser(index); 
    rowform.$cancel(); 
} 

现在你可以做你自己的东西,并调用形式$取消,如果你做。

3

另外,如果你看一下xeditable.js你会看到$取消()内部调用$ oncancel()看起来形式对oncancel属性和调用它提供的功能。因此,不是在控制器中处理表格,而是可以有:

<form editable-form name="rowform" onbeforesave="saveRole($data, $index)" oncancel="removeIfNewRow($index)" ng-show="rowform.$visible" class="form-inline" shown="inserted == role"> 
       <button type="submit" ng-disabled="rowform.$waiting" class="btn btn-primary"> 
        save 
       </button> 
       <button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default"> 
        cancel 
       </button> 
</form>