我正在使用https://github.com/Nijikokun/ractive.sortable.js向桌面添加可拖动排序功能。
var resources = [
{
rid: "22222225",
title: "Archive.zip",
filename: "222343.zip",
type: "foo",
duration: "10"
},
{
rid: "22222225",
title: "Archive.zip",
filename: "222343.zip",
type: "foo",
duration: "10"
}
...
]
<tbody id="resourceList" on-sortable='sort-items'>
{{#each resources:num}}
<tr rv-each-item="data.resources">
<td>
<i class="dragHandle glyphicon glyphicon-move">M</i>
</td>
<td class="rTitle">{{title}}</td>
<td class="rType">{{filename}}</td>
<td class="rType">{{type}}</td>
<td class="rDuration">
{{#if duration}}
<input type="number" min="10" step="1" value="{{duration}}"> seconds
{{/if}}
</td>
<td>
{{#if resources.length != 1 }}
<button class="btn" type="button" on-click='removeItem'><i class="deleteRow glyphicon glyphicon-trash"></i>
</button>
{{/if}}
</td>
</tr>
{{/each}}
</tbody>
拖动按预期工作 - 我只是想弄清楚如何提取新的排序顺序,并用它来更新数据数组中对象的顺序。我一直在玩ractive.observe - 但不能理解它......
答案 0 :(得分:1)
您不需要以任何方式更新阵列。可排序的插件将为您做到这一点。