I am using Lawnchair in an app I am creating in Cordova. I am having erattic problems when removing records ie, I code to remove the first record but the second is removed or I get Uncaught TypeError: Cannot set property 'key' of undefined. Has anyone had this problem or am I doing something wrong. If you run the script below and try to remove records in different sequences the problem will manifest. Any help would be appreciated. Thanks.
<!DOCTYPE html><html>
<head>
<title>Lawnchair</title>
<script type="text/javascript" src="js/lawnchair-0.6.1.js"></script>
</head>
<body>
<script type="text/javascript">
var tmpStore1 = new Array();
tmpStore1.push({ "ISBN":9781565926998,
"Title":"jquery",
"Book":"pdf",
"Qty":3,
"Value":12.46
} );
var tmpStore2 = new Array();
tmpStore2.push({ "ISBN":123456789,
"Title":"lawnchair",
"Book":"web",
"Qty":6,
"Value":5.67
} );
var tmpStore3 = new Array();
tmpStore3.push({ "ISBN":987654321,
"Title":"extjs",
"Book":"web",
"Qty":1,
"Value":8.45
} );
var viewData = Lawnchair( function(e){ //open the store
console.log('store ready ');
});
// viewData.nuke();
viewData.save({key:9781565926998, data:tmpStore1}); // save 1
viewData.save({key:123456789, data:tmpStore2}); // save 2
viewData.save({key:987654321, data:tmpStore3}); // save 3
// hash out to remove records individually
isbn = 9781565926998;
viewData.remove(isbn); //delete 1
isbn = 123456789
viewData.remove(isbn); //delete 2
isbn = 987654321
viewData.remove(isbn); //delete 3
viewData.each(function(record) {
console.log(record.data[0].ISBN+' - '+record.data[0].Title);
console.log(record);
});
</script>
</body>
To make it work isbn should be a string, ie: isbn = "9781565926998" or an object with a key value set to your isbn value. Give a try.