I have created the list based on the AJAX result. Basically dynamically add the items into the list. But In the second time ajax calling,the list item append to the previous items. I want to reload the list newly. It should contains results of second ajax calling.
I want to remove the all the list items alone.Not a list from the page.
Any one help me.
Code for dynamically add the list value:
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');
this should do the trick to clear the list.
P.S. If you intend to use jQuery, then use it.
If you want to remove everything, then why not use jQuery to do so?
$('#listview').empty();
This will help you create a iphone like swipe delete. This is in reference to http://forum.jquery.com/topic/adding-an-iphone-style-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]);
});
});
});
};
usage:
EXERCISEDESCRIPTION.swipeDelete('exerciseSetsListview',
function(e) {
EXERCISEDESCRIPTION.setsObj.splice(e,1);
EXERCISEDESCRIPTION.repopulateSets();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With