ngtable内联编辑,无法添加行?

时间:2014-06-19 03:18:49

标签: angularjs ngtable

了解ng-table网格。坚持如何添加新行:

$scope.addRow = function(add) {
      $scope.data.push(add)
      $scope.showAdd = false;
};

尝试将新对象添加到数据数组但不起作用?这有什么不对?

HTML:

<table class="noborder">
    <tr>
        <td rowspan="2">ID: {{add.id}}<input type="hidden" name="id" value="{{add.id}}"></td>
        <td>Firstname:</td>
        <td><input type="text" name="fn" class="w100" ng-model="add.fn"></td>
        <td>Description: </td>
        <td>Email:</td>
        <td><input type="text" name="em" class="w180" ng-model="add.em"></td>
        <td><input type="button" value=" save " ng-click="addRow(p);"></td>
    </tr>
    <tr>
        <td>Lastname:</td>
        <td><input type="text" name="ln" class="w100" ng-model="add.ln"></td>
        <td><input type="text" name="dc" class="w180" ng-model="add.dc"></td>
        <td>Phone: </td>
        <td><input type="text" name="ph" class="w120" ng-model="add.ph"></td>
        <td><input type="button" value=" cancel" ng-click="cancelEdit()"></td>
    </tr>
</table>

这是一个plunkr ref:http://plnkr.co/edit/9woANV?p=preview

1 个答案:

答案 0 :(得分:0)

在addRow.html中,您要添加变量'p',它始终计算为null。将其更改为“添加”。

e.g。

ng-click="addRow(add);"

plunkr:https://plnkr.co/edit/xEL78EZNGrD6GxE029X8?p=preview