我试图将ng-repeater中每行的id值转换为输入类型=“text”,以便能够保存表的排序顺序。但是我不知道如何提取id,所以我得到了列表的完整版本。
表格如下:
<table class="table table-striped">
<thead>
<tr>
<th class="position"></th>
<th>Specification Title</th>
<th>Last modified</th>
<th class="right">Used in</th>
</tr>
</thead>
<tbody ui-sortable="sortableOptions" ng-model="specsList">
<tr ng-repeat="spec in specsList">
<td class="position draggable"></td>
<td><a href="#/editSpec/{{spec.id}}">{{spec.title}}</a></td>
<td>{{spec.lastModified}}</td>
<td class="right color_green"><strong>{{spec.usedIn}}</strong> of 12 products</td>
</tr>
</tbody>
</table>
输入:
<input type="text" id="tableSortOrder" value="{{specsList}}">
输入文本中的当前值:
[{ “ID”: “123”, “标题”: “商标”, “上次更改时间”: “2012-08-14”, “usedIn”: “7”},{ “ID”: “789”, “标题”: “金额”, “上次更改时间”: “2010-07-22”, “usedIn”: “5”},{ “ID”: “456”, “标题”: “ISBN”, “lastModified”:“2010-02-24”,“usedIn”:“2”}]
我想要实现的目标:
123,789,456
感谢您的帮助!
答案 0 :(得分:1)
这是你想要的吗?:
<input type="text" id="tableSortOrder" value="{{ specsList.map(function(item){return item.id;}).join() }}" />
您也可以在过滤器中执行此操作,如下所示:
<input type="text" id="tableSortOrder" value="{{ specsList | splitIds }}" />
app.filter('splitIds', function() {
return function(ArrayWithIds) {
return ArrayWithIds.map(function(item){return item.id;}).join();
};
});
我已经制作了这个jsfiddle,以便你可以看到它是如何工作的:http://jsfiddle.net/d5ye9mus/2/