jQuery可排序列表不会序列化,为什么? [英] Jquery sortable list won't serialize, why?
问题描述
我正在Zend Framework应用程序中使用jquery实现可排序的图像列表. 我只是无法使用.sortable('serialize')方法返回比空字符串更多的内容.
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.
当我在应用程序之外尝试一些简单的示例时,它会起作用.
When I try with a few simple examples outside my application it works.
下面的代码片段是否被其他各种标签包裹起来很重要.我认为不应该.应该通过ID来找到无序列表,对吧?
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?
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);
}
});
});
推荐答案
http://api .jqueryui.com/sortable/#method-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.
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_2 will 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.
这篇关于jQuery可排序列表不会序列化,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!