我正在使用backbone.js、require.js 和Phonegap 开发一个应用程序。我在从模型访问 Phonegap api 时遇到问题。我的 index.html 文件如下所示:
<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>
在路由器的初始化函数中,我正在测试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);
}
这工作正常,我可以得到该值已设置并被检索。我也有一个登录状态模型。如下:
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, the value is');
console.log(value);
},
});
return {
LoginStatus: LoginStatus
};
});
当我从路由器的初始化函数调用实例化模型时,出现错误:
Uncaught illegal access at file:///android_asset/www/js/app/models/loginstatus.js
如何从我的模型访问 Phonegap api?