php Jquery 可排序列表不会序列化,为什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/965083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery sortable list won't serialize, why?
提问by markus
I'm implementing a sortable list of images with jquery in a Zend Framework application. I just can't get the .sortable('serialize') method to return more than an empty string.
我正在 Zend Framework 应用程序中使用 jquery 实现可排序的图像列表。我只是无法让 .sortable('serialize') 方法返回多个空字符串。
When I try with a few simple examples outside my application it works.
当我在我的应用程序之外尝试一些简单的例子时,它可以工作。
Does it matter that the snippet below is wrapped in various other and other tags. I think it shouldn't. The unordered list should be found just by the id, right?
下面的代码段是否包含在各种其他和其他标签中是否重要。我认为不应该。无序列表应该只能通过 id 找到,对吗?
HTML:
HTML:
<ul id="mylist">
<li id="1">
<div>
<img src="image_1.jpg" />
<p class="value_item">some text</p>
</div>
</li>
<li id="2">
<div>
<img src="image_2.jpg" />
<p class="value_item">some text</p>
</div>
</li>
</ul>
JavaScript:
JavaScript:
$(document).ready(function() {
$('#mylist').sortable({
update: function() {
var order = $('#mylist').sortable('serialize');
alert(order);
}
});
});
回答by jeroen.verhoest
http://api.jqueryui.com/sortable/#method-serialize
http://api.jqueryui.com/sortable/#method-serialize
If serialize returns an empty string, make sure the id attributes include an underscore. They must be in the form: "set_number" For example, a 3 element list with id attributes foo_1, foo_5, foo_2will serialize to foo[]=1&foo[]=5&foo[]=2. You can use an underscore, equal sign or hyphen to separate the set and number. For example foo=1 or foo-1 or foo_1 all serialize to foo[]=1.
如果 serialize 返回空字符串,请确保 id 属性包含下划线。它们必须采用以下形式:“set_number” 例如,id 属性为foo_1、foo_5、foo_2的 3 元素列表将序列化为 foo[]=1&foo[]=5&foo[]=2。您可以使用下划线、等号或连字符来分隔集合和数字。例如 foo=1 或 foo-1 或 foo_1 都序列化为 foo[]=1。
回答by Lathan
Jquery runs into problems when you use non-compliant ids.
当您使用不合规的 id 时,Jquery 会遇到问题。
Ids are not allowed to begin with a number. They can have numbers in them, just not as the first character.
ID 不允许以数字开头。他们可以有数字,只是不能作为第一个字符。
回答by DukeDrake
(link update) hi, I stumbled across a similiar problem a few days ago, though in my case it was important to keep the order of the elements intact. I coded a small plugin which will allow you to serialize ul and ol lists of arbitrary depth and complexity:
(链接更新)嗨,几天前我偶然发现了一个类似的问题,但在我的情况下,保持元素的顺序完整很重要。我编写了一个小插件,它允许您序列化任意深度和复杂性的 ul 和 ol 列表:

