11

当用户添加新行并单击取消按钮(不放置任何数据)时,是否有可能,该行将被删除。否则我怎么能改变取消按钮代码,因为这个使用angularJS的默认xeditable代码。(或者如果行为空,我怎么能调用删除函数?)

这是示例

取消按钮的HTML :

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

2 回答 2

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();
}

现在你可以做你自己的事情,如果你完成了调用表格 $cancel。

于 2014-01-24T17:23:11.283 回答
3

或者,如果您查看 xeditable.js,您会看到$cancel()内部调用$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>
于 2014-12-03T16:01:16.587 回答