【问题标题】:Angular-Xeditable loading page with all rows in Edit ModeAngular-Xeditable 加载页面,所有行都处于编辑模式
【发布时间】:2015-07-27 17:23:24
【问题描述】:

我第一次尝试 angular-xeditable 并设法让一切正常工作,除了页面在编辑模式下加载所有表格行并且 我需要默认行为。 (加载后单击 3 个取消按钮会显示我要创建的内容)。

我有一个精简的 plunker(没有 CRUD 方法),它显示了我的意思...plunker

我也使用 $scope 创建了相同的内容,但我不想使用 $scope ...plunker with $scope

这是我的看法:

<body ng-controller="DistributorsController as dist">
    <fieldset>
      <legend>Distributors</legend>
      <table class="table table-striped table-bordered">
        <tbody>
          <tr>
            <th style="width:22%;">Name</th>
            <th style="width:15%;">Phone</th>
            <th style="width:12%;">Email</th>
            <th style="width:6%;">&nbsp;</th>
          </tr>
          <tr ng-repeat="dis in dist.distributors" ng-dblclick="rowform.$show()">
            <td>
              <span editable-text="dis.name" e-name="name" e-form="rowform" e-style="width:100%;">
                  {{ dis.name || '--' }}
                </span>
            </td>
            <td>
              <span editable-text="dis.phone" e-name="phone" e-form="rowform" e-style="width:100%;">
                  {{ dis.phone|phone }}
                </span>
            </td>
            <td>
              <span editable-text="dis.email" e-name="email" e-form="rowform" e-style="width:100%;">
                  {{ dis.email || '--' }}
                </span>
            </td>
            <td style="white-space: nowrap">
              <!-- form -->
              <form editable-form="" name="rowform" onbeforesave="dist.saveRecord($data, dis.id)" ng-show="rowform.$visible" class="form-buttons form-inline" shown="inserted == distributor">
                <button type="submit" ng-disabled="rowform.$waiting">
                  <span class="glyphicon glyphicon-ok-sign" style="color:#006837;"></span>
                </button>
                <button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()">
                  <span class="glyphicon glyphicon-remove-sign" style="color: #990000;"></span>
                </button>
              </form>
              <div class="buttons" ng-show="!rowform.$visible">
                <span class="glyphicon glyphicon-trash" style="color: #990000;" ng-click="dist.removeRecord($index, dis.id)"></span>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
      <p>
        <a ng-click="dist.insertRecord()" class="btn btn-xs btn-default">
          <span class="glyphicon glyphicon-plus-sign" style="color:#006837;"></span>


 Add New</a>
      </p>
    </fieldset>
  </body>

和我的控制器

(function(){
  'use strict';
  angular
    .module('app')
    .controller('DistributorsController', DistributorsController);

    DistributorsController.$inject = ['$filter'];

    /* @ngInject */
    function DistributorsController($filter) {
      /* jshint validthis: true */
      var vm = this;

      vm.distributors = [
        {id: 1, name: "Jonah's Whale", phone: '3185551212', email: 'jwhale@distributors.org'},
        {id: 2, name: "Paul's Thorn", phone: '5015551212', email: 'pthorne@distributors.org'},
        {id: 3, name: "Lot's Wife", phone: '5045551212', email: 'lwife@distributors.org'}
      ];

    }
})();

【问题讨论】:

  • @isherwood,我能问一下你为什么编辑我的问题的标题吗?在我看来,具体(即角度可编辑)会有所帮助,因为不熟悉该技术的人甚至不必阅读该问题。放心,我不难过;只是好奇。
  • 如果合适,请在您的问题标题中使用标签。不要简单地随机附加或预先添加它们。如果我误解了你的标题,我深表歉意。许多人只是在他们的前面写上门框。更多:meta.stackexchange.com/questions/19190/…
  • 明白了。因为这个问题是 angular-xeditable 独有的,所以我觉得它在标题中是合适的。感谢您的建议。

标签: angularjs x-editable


【解决方案1】:

Doc Says

要同时显示多个可编辑元素并一次性提交 应该将它们包装到标签中。这 表单的名称属性将在范围内创建变量(正常角度 行为)和可编辑表单属性将添加一些方法 变量:

您需要在每个tr 上具有ng-form 属性,因为table 标签中不支持其他元素

标记

<tbody>
    <tr ng-form editable-form name="editableForm" 
        ng-repeat="dis in dist.distributors" ng-dblclick="rowform.$show()">
           ...................    
           ..editable input elements here..
           ...................
    </tr>
</tbody>

Wokring Plunkr

【讨论】:

  • 当我进行编辑时,我失去了双击以进入该行的编辑模式......不幸的是,这是一个显示停止器。规范需要双击(如 Excel(yuk!))而不是编辑按钮
  • 我分叉了随表格行文档一起提供的 jsFiddle,并对其进行了编辑以启用双击并删除了编辑按钮,这就是我需要的行为。但是,当我编辑它以使用 Controller As 时,它再次中断。 (jsFiddle:jsfiddle.net/wynnwade/t8w5u9ns/1)
  • @jgravois 只是想知道..为什么你不想要$scope
  • 我正在将应用程序从 $scope 转换为控制器,为 Angular 2.0 做准备
  • 我们有一个运维应用即将进入测试阶段,这是一笔巨大的投资,所以我尝试使用最新最好的一切,并在 2.0 成熟时尽可能轻松地升级。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-27
  • 1970-01-01
  • 1970-01-01
  • 2020-11-18
  • 2019-09-01
相关资源
最近更新 更多