如何在角度Js中使用内联编辑,而行中没有任何按钮

时间:2016-04-20 11:15:58

标签: javascript angularjs inline-editing

我有下表,

 $scope.idDetails = function(product){
        var ids={
            mainId : product.mainId,
            childId : product.childId
            };
            console.log(ids.childId);
             commerceService.getVariants(ids.childId).
                    success(function(data) {
                     toastr.success('Successfully saved', 'Awsome!', {
                         closeButton: true
                     });
                    $scope.variants=[{
                        type: "cloth",
                        name: data[0].name,
                        size: "10",
                        price: data[0].price,
                        qty: "1"
                    }];
                    console.log($scope.variants.name);
                    }).error(function(err) {
                        toastr.error('Saving detals was not Successful', 'Warning', {
                            closeButton: true
                        });
                    });
        }

获取数据的控制部分如下,

SELECT c.id, c.short_name,
MAX(CASE a.name when 'Nr' then atc.attribute_value END) as "Nr",
c.vat
FROM contractor c
LEFT JOIN attribute_to_contractor atc
ON  c.id = atc.fk_contractor
LEFT JOIN attribute a
ON  a.id = atc.fk_attribute
GROUP BY c.id, c.short_name, c.vat;

一切正常,但我想使用Angular Js内联编辑器来编辑表格中的行。首先,用户可以看到我从控制器获得的数据,然后用户应该能够编辑行。我通过互联网搜索,但我找到了使用按钮编辑和保存的内联编辑表。我不希望表格行中有任何按钮。我想将数据与模型绑定。因此,最后我可以通过模型从表中获取数据。请帮忙

1 个答案:

答案 0 :(得分:1)

在许多区域搜索后,我发现了一个不需要任何按钮编辑的内联编辑。代码如下,

<div class="md-dialog-main">
                        <table class="me-hours-table">
                            <thead>
                                <th>Product Type</th>
                                <th>Product Name</th>
                                <th>
                                    <select ng-model="selection">
                                        <option value="weight">weight</option>
                                        <option value="size">size</option>
                                    </select>
                                </th>
                                <th>Price</th>
                                <th>Qty</th>
                            </thead>
                            <tbody>

                                <tr ng-repeat="data in variants">
                                    <td
                                       inline-edit="data.sku"
                                       inline-edit-callback="skuUpdateHandler(newValue)"
                                       inline-edit-btn-edit=""
                                       inline-edit-on-blur="save"
                                       inline-edit-on-click></td>
                                    <td
                                       ng-model="data.name">{{data.name}}</td>
                                    <td
                                       inline-edit="data.sizeOrweight"
                                       inline-edit-callback="sizeUpdateHandler(newValue)"
                                       inline-edit-btn-edit=""
                                       inline-edit-on-blur="save"
                                       inline-edit-on-click></td>
                                    <td
                                       inline-edit="data.price"
                                       inline-edit-callback="priceUpdateHandler(newValue)"
                                       inline-edit-btn-edit=""
                                       inline-edit-on-blur="save"
                                       inline-edit-on-click></td>
                                    <td
                                       inline-edit="data.qty"
                                       inline-edit-btn-edit=""
                                       inline-edit-on-blur="save"
                                       inline-edit-on-click></td>
                                </tr>
                                    <td 
                                       inline-edit-callback="qtyUpdateHandler(newValue)"
                                       inline-edit-btn-edit=""
                                       inline-edit-on-blur="save"
                                       inline-edit-on-click></td>
                                </tr>

                            </tbody>
                        </table>
                    </div>

控制器如下,

$scope.skuUpdateHandler = function(newValue) {
  console.log(newValue);
};
$scope.sizeUpdateHandler = function(newValue) {
  console.log(newValue);
};
$scope.priceUpdateHandler = function(newValue) {
  console.log(newValue);
};

请安装ng-inline-edit以使用此方法。点击 https://github.com/tameraydin/ng-inline-edit安装ng-inline-edit