cordova - Access Phonegap API from Backbone.js model -


i'm developing app backbone.js, require.js , phonegap. i'm having problems accessing phonegap api model. index.html file looks this:

<html> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> <link href="topcoat/css/topcoat-mobile-light.min.css" rel="stylesheet"> <link href="css/styles.css" rel="stylesheet"> <link href="css/pageslider.css" rel="stylesheet"> <script type="text/javascript" src="cordova.js"></script> <script data-main="js/app" src="js/require.js"></script> </head>  <body></body>  </html> 

in initialize function of router, i'm testing phonegap api:

    initialize: function() {           window.localstorage.setitem("key", "some bloddy value");         var value = window.localstorage.getitem("key");          console.log('the value is');         console.log(value); } 

this works fine, can value set , retrieved. have logged in status model. follows:

define(function (require) {  "use strict";  var $                   = require('jquery'),     backbone            = require('backbone'),       loginstatus = backbone.model.extend({          defaults: {            loggedin: false,            api_key: null,            user_id: null        },         initialize: function () {          window.localstorage.setitem("key2", "some other value");         var value = window.localstorage.getitem("key2");         console.log('in init, value is');         console.log(value);        },      });  return {     loginstatus: loginstatus };  }); 

when call instantiate model initialize function of router, error:

uncaught illegal access @ file:///android_asset/www/js/app/models/loginstatus.js 

how can access phonegap api models?

you should add event listener deviceready event. inside listener should start backbone router. in way start using phonegap api when ready.

document.addeventlistener("deviceready", function(){      backbone.history.start();  }, false);  

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -