質問
Ajaxの結果に基づいてリストを作成しました。基本的にアイテムをリストに動的に追加します。ただし、Ajax呼び出しの2回目では、リスト項目は以前のアイテムに追加されます。リストを新しくリロードしたいです。 2番目のAJAX呼び出しの結果が含まれている必要があります。
すべてのリスト項目を単独で削除したいのですが、ページからリストを表示しません。
誰でも私を助けてくれます。
リスト値を動的に追加するコード:
var parent = document.getElementById('listview');
var listItem = document.createElement('li');
listItem.setAttribute('id','listitem_'+i);
listItem.innerHTML = "one";
parent.appendChild(listItem);
$(parent).listview("refresh");
解決
$('#listview').children().remove('li');
これにより、リストをクリアするためのトリックが必要です。
PS jQueryを使用する場合は、それを使用してください。
他のヒント
すべてを削除したい場合は、jqueryを使用してそうしてみませんか?
$('#listview').empty();
これにより、Swipe DeleteなどのiPhoneの作成に役立ちます。これはに関連しています http://forum.jquery.com/topic/adding-an-iphone-swipe-to-delete-button-to-a-listview
EXERCISEDESCRIPTION.swipeDelete = function(exerciseSetsListview, callback) {
var listViewJq = '#'+exerciseSetsListview;
$(listViewJq).children().each(function(){
var child = $(this);
var childId = child.attr('id');
var splitId = childId.split("_");
var childIdVar = '#'+childId;
var childIdBtnVar = splitId[0]+'_button_'+splitId[1];
var childIdBtnVarJq = '#'+childIdBtnVar;
$(childIdVar).bind('swiperight', function() {
$(childIdVar).prepend('<a href="#" id="'+childIdBtnVar+'" class="aSwipeBtn" data-theme="b" data-inline="true" data-role="button">Delete</a>');
$(childIdBtnVarJq).button();
$(childIdVar).unbind('swiperight');
$(childIdBtnVarJq).bind('click tap', function() {
$(childIdVar).remove();
var splitButtonId = childIdBtnVarJq.split("_");
callback(splitButtonId[2]);
});
});
});
};
利用方法:
EXERCISEDESCRIPTION.swipeDelete('exerciseSetsListview',
function(e) {
EXERCISEDESCRIPTION.setsObj.splice(e,1);
EXERCISEDESCRIPTION.repopulateSets();
});
あなたが質問を理解していた場合、新しいエントリを追加する前にListViewを空にしようとしています。これを行うことができます:
var parent = document.getElementById('listview');
//remove all childs here , or easyer with html()
parent.html('');
var listItem = document.createElement('li');
listItem.setAttribute('id','listitem_'+i);
listItem.innerHTML = "one";
parent.appendChild(listItem);
$(parent).listview("refresh");
function removeAllOptions(selectbox){
var i;
for(i=selectbox.options.length-1;i>=0;i--){
selectbox.remove(i);
}
}
所属していません StackOverflow