我使用的是带有jQuery属性的data-id UI排序。我知道您可以在类似于sortable('serialize')的东西中使用id="row_4",这对我确实有效,但我需要这样做。
sortable('serialize', {attribute: 'data-id'})给出一个空字符串sortable('toArray'), {attribute: 'data-id'})给出预期输出<div data-sortable="link/to/handler">
<div data-id="1">1</div>
<div data-id="2">2</div>
<div data-id="3">3</div>
<div data-id="4">4</div>
<div data-id="5">5</div>
</div>var container = $('[data-sortable]');
container.sortable({
items : "> [data-id]",
update : function() {
var postData = container.sortable('serialize', {
attribute: 'data-id'
});
alert(postData); // Nothing
var postData2 = container.sortable('toArray', {
attribute: 'data-id'
});
alert(postData2); // 1,3,4,5,2 etc.
}
});小提琴:http://jsfiddle.net/ogzw5pL2/
怎么回事?我百分之九十八肯定这之前起作用了。
发布于 2015-08-05 17:52:40
您需要key和value来实现serialize,但是您可以使用参数来覆盖默认行为并获得想要的结果。
在您的示例中,您可以设置所需的attribute、key和expression,以便它接受data-id,并使用定义的key和适当的值构建字符串。如下所示:
var postData = container.sortable('serialize', {
attribute: 'data-id',//this will look up this attribute
key: 'order',//this manually sets the key
expression: /(.+)/ //expression is a RegExp allowing to determine how to split the data in key-value. In your case it's just the value
});小提琴:http://jsfiddle.net/c2o3txry/
发布于 2015-08-05 17:46:29
如果没有“某某-n”形式的id值,“序列化”方法就不能工作。(您可以使用_或=而不是-。)
这样做的目的是为您提供一个查询字符串,该字符串的参数名称为“string”,-后面的值为值。
https://stackoverflow.com/questions/31839235
复制相似问题