使用Jaydata,我可以从odata服务填充我的简单本地数据库。该数据库具有组织表。
我也在使用AngularJs。以下代码从本地数据库获取组织,并将它们绑定到我的OrganziationIndex视图中引用的$ scope.Organizations。到目前为止,我已经在Chrome,iOS7上的Safari和内置于ICS的Android浏览器中对此进行了测试,并且它在每个浏览器中均可正常运行。
var localDB = new InspecTechDB({
name: 'local',
databaseName: 'InspecTech'
});
app.controller('OrganizationIndex', function ($scope, $data) {
$scope.organizations = [];
//wait until the localDB is ready, then get the Organizations
$.when(localDB.onReady())
.then(function () {
$scope.inspectechdb = localDB;
$scope.organizations = localDB.Organizations.toLiveArray();
$scope.message = "Organizations fetched from local store. Click one of them!";
});
});
但是,在IE11中,我在控制台上收到一条错误消息,该消息在此行中仅显示“Pure Class”,并且组织未在视图中列出:
scope.organizations = localDB.Organizations.toLiveArray();
谷歌搜索显示没有结果:Google Search
我已经通过控制台记录验证了该表是从odata服务填充的。我发现如果我更改下面显示的代码(从本地数据库更改为odata服务),则错误消失:
var remoteDB = new InspecTechDB({
name: 'oData',
oDataServiceHost: '/odata'
});
app.controller('OrganizationIndex', function ($scope, $data) {
$scope.organizations = [];
//wait until the localDB is ready, then get the Organizations
$.when(remoteDB.onReady())
.then(function () {
$scope.inspectechdb = remoteDB;
$scope.organizations = remoteDB.Organizations.toLiveArray();
$scope.message = "Organizations fetched from local store. Click one of them!";
});
});
我打算让应用程序脱机运行,因此我需要能够从本地数据库而不是odata服务中获取组织。
有人能指出正确的方向,我需要做些什么来使这项工作在IE?
谢谢, 麦克
更新1: 我在Firefox中观察到同样的错误。
更新2: 如果我像这样更改提供程序,我在Chrome中观察到相同的错误:
var localDB = new InspecTechDB({
name: 'indexedDb',
databaseName: 'InspecTech'
});
因此问题并非特定于IE,更像是特定于IndexedDB提供程序。
UDPATE 3: 这是一些解决方法代码。我仍然想知道.toLiveArray()的问题。
var localDB = new InspecTechDB({
name: 'local',
databaseName: 'InspecTech'
});
app.controller('OrganizationIndex', function ($scope, $data) {
$scope.organizations = [];
//wait until the localDB is ready, then get the Organizations
//$.when(localDB.onReady())
//.then(function () {
// $scope.inspectechdb = localDB;
// $scope.organizations = localDB.Organizations.toLiveArray()
// .then(function () {
// $scope.message = "Organizations fetched from local store. Click one of them!";
// });
//});
//this code replaces the above code since I can't make toLiveArray work w/ indexedDB provider
$.when(localDB.onReady())
.then(function () {
var organizations = localDB.Organizations.toArray();
return $.when(organizations)
.then(function (orgs) {
$scope.$apply(function () {
orgs.forEach(function (organization) {
$scope.organizations.push(organization);
});
});
});
});
});