我正在尝试为表格创建内联编辑(类似于angular-xeditable),但我只希望一次只允许一行可编辑。目前,您可以将任意数量的行设置为编辑模式。角度内联编辑表单身
选项
请编辑模式的行的列表,并尽快作为一个新行被选中进行编辑,通过循环列表,并强行退出编辑模式出来,放置请求在编辑模式下行并将其添加到列表中。这基本上允许最多1行列在列表中,从而导致一行可以一次编辑。但是我没有说明如何让行退出编辑模式。
有一个退出编辑模式的取消按钮。所以也许可以使用jquery(或angular.element)来获取所有取消按钮的列表并实际点击它们 - 再次强制退出编辑模式下的行,但这可能会减慢大表的速度,因为它会点击取消即使在编辑模式下也不行。
<table class="table table-striped">
<thead>
<tr>
<th id="th-name">Name</th>
<th id="th-age">Age</th>
<th id="th-actions">Actions</th>
</tr>
</thead>
<tr ng-repeat="contact in model.contacts">
<td>
<span ng-show="edit != true">{{contact.name}}</span>
<input ng-show="edit" type="text" ng-model="model.selected.name" class="form-control" placeholder="Name">
</td>
<td>
<span ng-show="edit != true">{{contact.age}}</span>
<input ng-show="edit" type="text" ng-model="model.selected.age" class="form-control" placeholder="Name"></td>
<td>
<button ng-show="edit != true" id="table-edit" ng-click="edit = true; editContact(contact)" uib-tooltip="Delete" tooltip-trigger="mouseenter" tooltip-placement="bottom"><i class="fa fa-fw fa-pencil"></i></button>
<button ng-show="edit" id="table-save" ng-click="edit = false; saveContact($index)" uib-tooltip="Delete" tooltip-trigger="mouseenter" tooltip-placement="bottom"><i class="fa fa-fw fa-floppy-o"></i></button>
<button ng-show="edit" id="table-cancel" ng-click="edit = false; reset()" uib-tooltip="Delete" tooltip-trigger="mouseenter" tooltip-placement="bottom"><i class="fa fa-fw fa-trash"></i></button>
</td>
</tr>
</table>
这里是一个plunker演示(允许所有行是在编辑模式下):Plnkr Demo`
这里是我想达到什么样的工作演示,但它是使用模板。它会根据我的喜好调用getTemplate太多次(每次运行摘要时都会调用它 - 单击按钮,键入,显示工具提示)。 Working Demo (Using templates)
良好的解决方法。我将你的'重做显示'循环移到重置函数,因为取消编辑也应该显示所有按钮(http://plnkr.co/edit/mTa8EPmuwEOw1DBHLAHN?p=preview)。但正如您从演示中使用模板可以看到的,理想的期望是显示所有按钮,并且能够在其他行上单击编辑而不必保存/取消 –
只需更改显示和隐藏的元素('eles')作为输入文本框。另外,您还必须为保存内容的跨度添加类名称。逻辑应该是相同的。 –
它仍然没有达到预期的结果(显示所有数据和按钮,并且能够点击任何编辑按钮进入相应行的编辑模式)。请参阅我的回答,如果您有任何反馈意见,我们非常欢迎和赞赏!谢谢你的帮助! –