javascript - How to load a db context in another Html page using YDN-DB? -
i've loaded data on first page:
<script src="/scripts/jquery-1.5.1.min.js" type="text/javascript"></script> <script src="/scripts/modernizr-1.7.min.js" type="text/javascript"></script> <script src="/scripts/ydn.db-jquery-0.7.5.js" type="text/javascript"></script> <script src="/scripts/jquery.mousewheel.js"></script> ... var schema = { stores: [{ name: 'products', keypath: 'cdproduto', autoincrement: false, indexes: [ { keypath: 'cdcategoria' }, { keypath: 'dtultimaatualizacao' }] }] }; var db = new ydn.db.storage('db-test', schema); db.clear().done(function (num) { db.add('products', [<%=jsonproducts%>]); });
the <%=jsonproducts%> prints json c# back-end.
i can load information this, works:
db.get('products', '2').always(function (record) {...
after, in same browser , session, when try load second page (/catalogo.html), load same product '2' key, this:
<script src="/scripts/jquery-1.5.1.min.js" type="text/javascript"></script> <script src="/scripts/modernizr-1.7.min.js" type="text/javascript"></script> <script src="/scripts/ydn.db-jquery-0.7.5.js" type="text/javascript"></script> <script src="/scripts/jquery.mousewheel.js"></script> ... var db = new ydn.db.storage('db-test'); db.get('products', '2').done(function (value) { console.log(value); });
it returns 'undefined' on console. have no clues.
besides, im using html cache manifest on both pages
<html manifest="/home/manifest">
and testing under local server, acessing localhost , port 60873, example.
am missing something? ain't right way open existing ydn-db?
thanks!
you not missing , should work. should check indexeddb content on resource panel of dev console.
you should initialize in second page /catalogo.html in first page, i.e,
var db = new ydn.db.storage('db-test', schema);
changing schema drop tables. such data lost occur when database constraint not met. triggered library or browser itself.
it practice check database connection before using follow:
db.addeventlistener('ready', function (event) { var is_updated = event.getversion() != event.getoldversion(); if (is_updated) { console.log('database connected new schema'); } else if (isnan(event.getoldversion())) { console.log('new database created'); } else { console.log('existing database connected'); } // heavy database operations should start this. });
Comments
Post a Comment