使用 jquery 将可拖动站点地图保存到数据库
我有一个问题,我找到了一个很棒的脚本,我想将其用于我的网站,但我不知道如何将其保存到我的数据库中,链接 这里,有人能给我指出正确的方向吗? 谢谢
看一下演示。我希望能够对列表进行排序,然后将其保存到我的数据库中。
有一个函数历史记录,但我就是不明白
`var sitemapHistory = {
stack: new Array(),
temp: null,
//takes an element and saves it's position in the sitemap.
//note: doesn't commit the save until commit() is called!
//this is because we might decide to cancel the move
saveState: function(item) {
sitemapHistory.temp = { item: $(item), itemParent: $(item).parent(), itemAfter:
$(item).prev() };
},
commit: function() {
if (sitemapHistory.temp != null) sitemapHistory.stack.push(sitemapHistory.temp);
},
//restores the state of the last moved item.
restoreState: function() {
var h = sitemapHistory.stack.pop();
if (h == null) return;
if (h.itemAfter.length > 0) {
h.itemAfter.after(h.item);
}
else {
h.itemParent.prepend(h.item);
}
//checks the classes on the lists
$('#sitemap li.sm2_liOpen').not(':has(li)').removeClass('sm2_liOpen');
$('#sitemap li:has(ul li):not(.sm2_liClosed)').addClass('sm2_liOpen');
}
}
`
I have a question, I found a great script that I want to use for my website but I don't know how to save it to my database, the link here, could someone point me to the right direction?
Thanks
Take a look at the demo. I want to be able to sort the list and then save it to my database.
There is a function history but I just can't figure it out
`var sitemapHistory = {
stack: new Array(),
temp: null,
//takes an element and saves it's position in the sitemap.
//note: doesn't commit the save until commit() is called!
//this is because we might decide to cancel the move
saveState: function(item) {
sitemapHistory.temp = { item: $(item), itemParent: $(item).parent(), itemAfter:
$(item).prev() };
},
commit: function() {
if (sitemapHistory.temp != null) sitemapHistory.stack.push(sitemapHistory.temp);
},
//restores the state of the last moved item.
restoreState: function() {
var h = sitemapHistory.stack.pop();
if (h == null) return;
if (h.itemAfter.length > 0) {
h.itemAfter.after(h.item);
}
else {
h.itemParent.prepend(h.item);
}
//checks the classes on the lists
$('#sitemap li.sm2_liOpen').not(':has(li)').removeClass('sm2_liOpen');
$('#sitemap li:has(ul li):not(.sm2_liClosed)').addClass('sm2_liOpen');
}
}
`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您需要自己创建 HTML 站点地图。它必须类似于页面上的示例:
展开/折叠 ...
然后,您包含页面中的脚本并运行它。
不确定这一切与您的数据库有什么关系。
First you need to create a sitemap in HTML yourself. It has to look like the example on the page:
<ul id=”sitemap”> <li> <dl> <dt><a href=”#”>expand/collapse</a> ...
Then you include the script from the page and run it.
Not sure what all this has to do with your database.
一种可能的解决方案是向每个行元素添加一个 linkID 和一个parentID。然后,当您保存更改时,请在后端对表进行更新。这将涵盖父母/孩子的关系。至于排序,我还在考虑。
一个有价值的资源是 jQuery Sortable 文档: http://jqueryui.com/demos/sortable/
A possible solution would be to add a linkID and a parentID to each line element. Then when you save the changes, make the updates to your table on the back end. That would cover the parent / child relationships. As for the sorting order, I'm still thinking about that.
A valuable resource is the jQuery Sortable document : http://jqueryui.com/demos/sortable/