javascript - 如何在行中没有任何按钮的情况下在 Angular Js 中使用内联编辑

标签 javascript angularjs inline-editing

我有下表,

<div class="md-dialog-main">
                        <table class="me-hours-table">
                            <thead>
                                <th>Product Type</th>
                                <th>Product Name</th>
                                <th>
                                    <select>
                                        <option  style="background-color:'#FF0000'">weight</option>
                                        <option  style="background-color:'#FF0000'">size</option>
                                    </select>
                                </th>
                                <th>Price</th>
                                <th>Qty</th>
                            </thead>
                            <tbody>
                                <tr ng-repeat="data in variants">
                                    <td>{{data.type}}</td>
                                    <td>{{data.name}}</td>
                                    <td>{{data.size}}</td>
                                    <td>{{data.price}}</td>
                                    <td>{{data.qty}}</td>
                                </tr>

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

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

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

一切正常,但我想使用 Angular Js 内联编辑器来编辑表中的行。首先,用户可以看到我从 Controller 获取的数据,然后用户应该能够编辑行。我通过互联网进行搜索,但发现内联编辑表使用按钮进行编辑和保存。我不想在表格行中出现任何按钮。我想将数据与模型绑定(bind)。这样最后我就可以通过模型从表中获取数据。请帮忙

最佳答案

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

<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>

Controller 如下,

$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

关于javascript - 如何在行中没有任何按钮的情况下在 Angular Js 中使用内联编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36742112/

相关文章:

javascript - 如果在手机设置中禁用了 javascript,phonegap + jquerymobile 应用程序会工作吗?

javascript - AngularJS 条件格式化 Ng-repeat

javascript - 使用内联文本编辑更新数据库

javascript - 在 span 和其他内联标签上启用 CKEditor4 内联

javascript - 为什么我无法在控制台日志中添加整数和变量?

javascript - 如何使用Chrome扩展存储API进行CRUD操作?

javascript - Rails 4.1 中将 bug Coffeescript 渲染为 js?

angularjs - ionic 导航栏按钮 - 右侧

php - 如何访问从 PHP 中的 HTTP POST 请求获取的数组对象的属性?

javascript - 在 IE10 中使用 CKEditor 内联编辑 TD