2014-01-24 35 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>