Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello

I am adding some data on data base problem After adding i need to show on list view.I need to remove all data from list before rendering again .how to remove data from list?

Hete is my code

JavaScript
$(document).ready(function() {
                   
                     $.mobile.loading('hide');
                     onDeviceReady();
                     });  

//document.addEventListener("deviceready", onDeviceReady, false);
    var db = "";
     //will create database Dummy_DB or open it
 
    //function will be called when device ready
    function onDeviceReady(){
         db = window.openDatabase("Casepad", "1.0", "Casepad", 200000);
         db.transaction(queryDB,errorCB);
       
       //   db.transaction(populateDB, errorCB, successCB);
    }
    function insertData(){
    db.transaction(populateDB, errorCB, successCB);
    }
   
    //create table and insert some record
    function populateDB(tx) {
        tx.executeSql('CREATE TABLE IF NOT EXISTS CaseTable (id INTEGER PRIMARY KEY AUTOINCREMENT, CaseName TEXT NOT NULL,CaseDate INTEGER ,TextArea TEXT NOT NULL)');
        tx.executeSql('INSERT INTO CaseTable(CaseName,CaseDate,TextArea) VALUES ("'+$('#caseNameValue').val()+'", "'+$('#caseDate').val()+'","'+$('#caseTextArea').val()+'")');
    }
 
    //function will be called when an error occurred
    function errorCB(err) {
        alert("Error processing SQL: "+err.code);
    }
 
    //function will be called when process succeed
    function successCB() {
        alert("success!");
        db.transaction(queryDB,errorCB);
    }
 
    //select all from SoccerPlayer
    function queryDB(tx){
        tx.executeSql('SELECT * FROM CaseTable',[],querySuccess,errorCB);
    }
 
    function querySuccess(tx,result){
     var len = result.rows.length;
     
      for (var i=0; i<len;>              $('#folderData').append(
               '<ul><li class="row" id="' + i + '">' + '<a href="#">' + '<img src="img/Blue-Folder.png">' + '<h2>'+result.rows.item(i).CaseName+'</h2>' + '<p>'+result.rows.item(i).CaseDate+'</p>' + '<p>'+result.rows.item(i).TextArea+'</p>'+'<span class="ui-li-count">'+ i+'</span></a>' + '</li></ul>'
            );
        } 
        $('#folderData').listview('refresh');
 
    }

   $("#Cancel").click(function() {
                    $('.ui-dialog').dialog('close')
                    $.mobile.changePage($("#Home"), {
                    transition: "pop",
                    reverse: false,
                    changeHash: false
                   });
                   });
                   
                    
                   $("#CancelSettingButton").click(function() {
                   $.mobile.changePage($("#Home"), {
                    transition: "slide",
                    reverse: false,
                    changeHash: false
                    });
                    });

<!--<-------------------Cancel Button Functionality End----------------------------------------->-->
<!-----------------------Add Button Functionality---------------------------------------------------->
JavaScript
$("#AddButton").click(function() {
  var isvalid=true;
  if(isvalid){

  insertData();
  $.mobile.changePage($("#Home"), {
  transition: "slide",
  reverse: false,
  changeHash: false
  });
   }
 });
Posted
v2

1 solution

I believe $('#mylist').empty(); will empty a list view. Is this just jquery ? It looks to me like you're using an additional library to do what you want.
 
Share this answer
 
Comments
ravi1989h 18-Jun-13 20:58pm    
How to check table exist or not? actually starting there is no table in so i don't need to render it gives undefined error ?can you check this error
Christian Graus 18-Jun-13 21:00pm    
the way that jquery works, if your element called 'mylist' does not exist, this code just does nothing.
ravi1989h 18-Jun-13 21:08pm    
$('#mylist').empty(); work
ravi1989h 18-Jun-13 21:09pm    
But i am appending dynamically data .
Christian Graus 18-Jun-13 21:10pm    
Right, so what is the issue ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900