項目のリストを表示する jQuery Mobile アプリがあります。項目を選択して、上下のボタンをクリックすると上下に移動できます。
ボタンをクリックしてアイテムを上下に移動すると、表示されているアイテムとそのアイテム ID が入れ替わります。次に、アイテムによって移動されたステップを含む ajax 投稿メッセージを送信します。
私が見たのは、クリックが速すぎると、アイテムが予期したとおりに動かない場合があるということです。また、アイテム ID のスワッピング操作の途中で関数が中断されたかのように、アイテム ID が重複する場合もあります。
これは既知の機能ですか? これを回避する解決策はありますか?
アイテムを移動するコードは次のとおりです
$("#btnListUp").on( "click", function(evt)
{
if( selectedItem && !selectedItem.hasClass('ui-first-child') )
{
var prev = selectedItem.prev();
var prevId = prev.attr('item-id');
var thisId = selectedItem.attr('item-id');
var step = (parseInt(prevId) - parseInt(thisId))+'';
prev.attr('item-id', thisId );
selectedItem.attr('item-id', prevId );
prev.detach().insertAfter(selectedItem);
$('#ShopList').listview('refresh');
$.ajax( {type: 'POST', url: thisId+'/moveUp', data : step,
contentType :'applicatio/octet-stream' } );
}
});
$("#btnListDown").on( "click", function(evt)
{
if( selectedItem && !selectedItem.hasClass('ui-last-child') )
{
var next = selectedItem.next();
var nextId = next.attr('item-id');
var thisId = selectedItem.attr('item-id');
var step = (parseInt(nextId) - parseInt(thisId))+'';
next.attr('item-id', thisId );
selectedItem.attr('item-id', nextId );
next.detach().insertBefore(selectedItem);
$('#ShopList').listview('refresh');
$.ajax( {type: 'POST', url: thisId+'/moveDown', data : step,
contentType :'applicatio/octet-stream' } );
}
});