我在 Cordova 创建的应用程序中使用 Lawnchair。我在删除记录时遇到了不稳定的问题,即,我编写了删除第一条记录的代码,但第二条记录被删除了,或者我得到了 Uncaught TypeError: Cannot set property 'key' of undefined。有没有人遇到这个问题或者我做错了什么。如果您运行下面的脚本并尝试以不同的顺序删除记录,则会出现问题。任何帮助,将不胜感激。谢谢。
<!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>