jQueryUIの並べ替え可能なリストの値を格納する非表示のフォームフィールドがあります。
<input name="asw_options[asw_icon_order]" type="hidden" value="<?php echo $aswicons ?>" />
ソートされたリストの順序を保存するjQuery関数があります。
/* Social Networking Icon Sorter */
var itemList = $('#asw-sortable');
itemList.sortable({
update: function(event, ui) {
$('#loading-animation').show(); // Show the animate loading gif while waiting
opts = {
url: ajaxurl, // ajaxurl is defined by WordPress and points to /wp-admin/admin-ajax.php
type: 'POST',
async: true,
cache: false,
dataType: 'json',
data:{
action: 'item_sort', // Tell WordPress how to handle this ajax request
order: itemList.sortable('toArray').toString() // Passes ID's of list items in 1,3,2 format
},
success: function(response) {
$('#loading-animation').hide(); // Hide the loading animation
//$('#asw_options[asw_icon_order]').val(itemList.sortable('toArray').toString()); // Update hidden field with new values
$('input[name=asw_options[asw_icon_order]]').val(itemList.sortable('toArray').toString());
return;
},
error: function(xhr,textStatus,e) { // This can be expanded to provide more information
alert(e);
// alert('There was an error saving the updates');
$('#loading-animation').hide(); // Hide the loading animation
return;
}
};
$.ajax(opts);
}
});
保存されたデータは次のように保存されます。
Delicious、Twitter、Facebook、Googleplus、Stumbleupon、Pinterest、LinkedIn、Youtube
すべてがうまく機能しています。フィールドを並べ替えると、jQueryを介して保存が自動的に行われます。
私の問題は、上に保存されている非表示フィールドが、jQueryが注文の新しい保存を正常に実行した後、jQueryを介して動的に更新できる必要があることです。
これはWordPressプラグインなので、非表示の入力フィールドを更新する必要があります。ユーザーが[保存]ボタンを押すと、非表示のフィールドの最初の「値」であるため、古い値が保存されるためです。
jQueryコードでわかるように、「Success」関数にコードを追加してから非表示フィールドを更新できると思いましたが、機能しません。
どんな助けでも大歓迎です。