更新数据对象 ractive.js ractive.sortable.js
updating data object ractive.js ractive.sortable.js
我正在使用 https://github.com/Nijikokun/ractive.sortable.js 将拖动排序table 功能添加到 table。
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 - 但无法理解它....
您应该不需要以任何方式更新数组。 sortable 插件将为您做到这一点。
我正在使用 https://github.com/Nijikokun/ractive.sortable.js 将拖动排序table 功能添加到 table。
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 - 但无法理解它....
您应该不需要以任何方式更新数组。 sortable 插件将为您做到这一点。