jQuery UI 可排序:从数组加载顺序
有没有一种方便的方法来加载存储的 jQuery UI 可排序列表的顺序?
我不想在服务器端执行此操作(服务器的额外复杂性/工作),并且由于唯一使用该列表的用户将拥有 javascript,因此不妨利用 javascript 在页面加载时对其进行重新排序。
所需的场景:
- 所有数据都使用 persistjs 存储为普通的 javascript 数组,或在页面加载时发送到客户端(作为本机数组)。
- 该列表应该是静态 HTML(对非 js 客户端友好)(并且不应附加到空列表,正如前面问题中的其他用户所建议的那样)
- 如果没有存储首选项,则不会发生任何情况。正常列表保持原样。
有什么想法吗?我认为这个问题将使很多用户受益,所以我希望有一个非常优雅、简单的解决方案(没有像删除库存列表然后将配置附加到新列表等混乱的黑客行为)。最好是只查看 ID 数组的东西(尽可能好(可能会添加一些项目,可能会删除一些项目))并将它们按相同的顺序排列。
谢谢! <代码>=]
Is there a convenient way to load the order of a stored jQuery UI Sortable list?
I'd prefer not to do this server side (extra complication/work for the server), and since the only users that would be resorting the list will have javascript, might as well utilize javascript to reorder it on page load.
The desired scenario:
- All data is stored as a normal javascript array using persistjs or sent to the client on page load (as a native array).
- The list should be static HTML (friendly to non-js clients) (and should not be appended to an empty list, as other users in previous questions suggest)
- If there's no stored preference, nothing happens. The normal list is just left as is.
Any ideas? I think this question will benefit a LOT of users, so I'm hoping for a very elegant, simple solution (no messy hacks like deleting a stock list then appending the configuration to a new one). Preferably something that just looks at an array of IDs and (as best as possible (some items may be added, some may be removed)) and puts them in the same order.
Thanks! =]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在页面按照您想要的方式加载后,您必须重新排序。并且您必须以任何方式在服务器端构建客户端排序的数组。
我认为最好以服务器端应有的方式显示可排序项目。该列表应该是静态 HTML(对非 js 客户端友好)你说的是吧?
如果您真的坚持在客户端浏览器上执行此操作(我不同意),请阅读 - jQuery.sortable.通过JS改变顺序
You will have to reorder it after the page loads the way you want it. And you will have to build the array for the client side ordering on the server side any way.
I think it is better to just show the sortable items in the way they should appear on the server side. The list should be static HTML (friendly to non-js clients) you said that, right?
If you really insist to do it on the client browser (with which I disagree), read that - jQuery.sortable. change the order by JS