JavaScript Lawnchair library.. stored as same "table"?
I am using Lawnchair JavaScript library. Reference here http://westcoastlogic.com/lawnchair/
In below code, because i passed different id, TABLE1 and TABLE2.. I expect dao1 and dao2 are completely be stored as 2 different objects / storage. But the fact is they're referring to the same thing.. and any "save" action from dao1 or dao2, will be stored at the same "Lawnchair".
i.e. (dao1.all and dao2.all will return same array).
Appreciate for your big/small idea / suggestion.. Thanks!!
<script src="javascripts/lib/Lawnchair.js" type="text/javascript"></script>
<script src="javascripts/lib/adaptors/WebkitSQLiteAdaptor.js" type="text/javascript"></script>
<script src="javascripts/lib/adaptors/DOMStorageAdaptor.js" type="text/javascript"></script>
<script src="javascripts/lib/adaptors/LawnchairAdaptorHelpers.js" type="text/javascript"></script>
var dao1 = new Lawnchair('TABLE1');
dao1.nuke(); // Clear persistent storage.
dao1.save({111: '222'});
var dao2 = new Lawnchair('TABLE2');
dao2.nuke(); // Clear persistent storage.
dao2.save({333: '444'});
dao1.all(function(a) {
console.log("dao1")
console.log(a)
});
dao2.all(function(a) {
console.log("dao2")
console.log(a)
});
w开发者_如何学编程ill produce something like below in Java Console
dao1
m-account.js:112[
Object
333: "444"
key: "ACF3A299-E986-4993-915F-A62FF009E846"
__proto__: Object
]
m-account.js:116
dao2
m-account.js:117[
Object
333: "444"
key: "ACF3A299-E986-4993-915F-A62FF009E846"
proto: Object
Lawnchair works fine:
http://jsfiddle.net/ambiguous/D4u57
I think you might be checking the wrong things (i.e. array length rather than contents), or putting one object in two Lawnchair databases, or perhaps you're not including all of the Lawnchair JavaScript files (there are several in my jsfiddle and I had to pull that list out of one of the Lawnchair examples).
Lawnchair is a cross mobile device key-value data store that insulates you from worrying about what platform your code is on.
You are trying to bend LawnChair in to doing something that it isn't designed to do.
You need to do full HTML5 database SQL.
精彩评论