我正在使用 jQuery UI 可排序data-id
属性。我知道你可以使用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.
}
});
Fiddle: http://jsfiddle.net/ogzw5pL2/ http://jsfiddle.net/ogzw5pL2/
这是怎么回事?我 98% 确信这之前是有效的。
你需要key
and value
for serialize
,但您可以使用参数来覆盖默认行为并获得想要的结果。
根据您的情况,您可以设置attribute
, key
and 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
});
Fiddle: http://jsfiddle.net/c2o3txry/ http://jsfiddle.net/c2o3txry/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)