我目前正在使用id
值div
標籤serialize
,即:使用類序列化?
HTML:
<div class="column">
<div id="portlet_1">some content here</div>
<div id="portlet_2">some content here</div>
<div id="portlet_3">some content here</div>
</div>
的jQuery:
$(this).sortable('serialize', {key: 'item'})
這工作正常。
的問題是,我需要讓用戶動態選擇哪個porlet他/她想要在屏幕上,他們可以在屏幕上有相同的Portlet多次,如果他們想,即:
HTML:
<div class="column">
<div id="portlet_1">some content here</div>
<div id="portlet_1">some content here</div>
<div id="portlet_1">some content here</div>
<div id="portlet_2">some content here</div>
<div id="portlet_2">some content here</div>
<div id="portlet_3">some content here</div>
</div>
由於相同的id
s,導致很多問題。
現在,我已經改變了結構,使用class
ES代替id
S,即:
HTML:
<div class="column">
<div class="portlet_1">some content here</div>
<div class="portlet_1">some content here</div>
<div class="portlet_1">some content here</div>
<div class="portlet_2">some content here</div>
<div class="portlet_2">some content here</div>
<div class="portlet_3">some content here</div>
</div>
怎樣基礎上,class
,而不是id
序列化?
這是因爲它系列化基於id
S的不使用的代碼更完整的提取物:
的jQuery:
$(".column").sortable({
connectWith: '.column',
update: function(event, ui) {
var that = this;
$.ajax({
url: 'some web service here',
type: 'POST',
data: { strItems:$(that).sortable('serialize', {key: 'item'}) },
error: function(xhr, status, error) {
//some error message here
},
success: function() {
//do something on success
}
});
}
});
對不起,忘了提,我使用的是舊jquery版本1.4。
如何可以在第一個例子中正常工作,如果你送'項目= 1項= 2項= 3'到服務器?你打算最終得到什麼?就像'item = 1&item = 1&item = 1&item = 2&item = 2&item = 3'? – VisioN
當我得到'item = 1&item = 2&item = 3'時,我將它分開並相應地在服務器級別使用它。是的,根據上面的示例中的HTML,您展示的最終示例正是「item = 1&item = 1&item = 1&item = 2&item = 2&item = 3」後面的內容。 – oshirowanen
然後最簡單的就是更新你的jQuery並使用'attribute'選項(如@JBRTRND答案):http://jsfiddle.net/WTTsB/。 – VisioN