2011-10-11 78 views
0

我的代码:Jquery tableDnD - 如何创建一个带有ID和位置的ajax?

<script type="text/javascript"> 
$(document).ready(function() { 
    // Initialise the table 
    $('#admintabel').tableDnD({ 
     onDrop: function(table, row) { 

     } 
    }); 

}); 
</script> 

如何创建一个参数的位置和ID Ajax调用示例/sort有这样的:[position, ID] onDrop?我的桌子应该如何。

更新:

我想创建一个数组:

BREDBANDS[id] 1 
BREDBANDS[id] 2 
BREDBANDS[id] 3 

我目前的测试数据:

data: { 
        BREDBANDS: [1, 2, 3]     }, 

而且它发布这样的:

BREDBANDS[] 1 
BREDBANDS[] 2 
BREDBANDS[] 3 

这是给500错误。

我的Rails应用数据被发布到:

def sort 
    params[:bredbands].each_with_index do |id, index| 
    Bredband.update_all(['position=?', index+1], ['id=?', id]) 
    end 
    render :nothing => true 
end 

回答

1

很难理解你实际上问,但做一个Ajax请求应该在任何这两种方式来完成:

$.ajax({ 
    type: "GET", 
    url: "/sort?" + $.tableDnD.serialize(), 
    success: function(){ 
     ... 
    } 
}); 

$.ajax({ 
    type: "POST", 
    url: "/sort", 
    data: $("tr", "$admintabel").map(function(){ 
     return this.id; 
    }), 
    success: function(){ 
     ... 
    } 
}); 

但是,因为它似乎你需要提供的ID给您TR个元素。那么你应该可以这样称呼:

$.tableDnD.serialize(); 

它将序列化表的数据和它的行ID。

+0

如何发布所有IDS的数组? –

+0

这是我的表格http://pastie.org/2675438我想发布IDS,并在我的操作中使用索引来更新订单。 –

+0

@Railsbeginner:查看我编辑的答案。并检查taleDnD的例子和代码背后的代码,你会看到它是如何工作的。 –

相关问题