Sqlite 使用Azure移动应用程序的ionic 2脱机数据同步抛出类型错误:无法读取属性';openDatabase';未定义的
我已经使用visual studio模板创建了ionic 2应用程序,并尝试在Azure移动应用程序功能中开发脱机数据同步。 我已经安装了节点“azure移动应用程序客户端模块”和 从“azure移动应用程序客户端”使用asSqlite 使用Azure移动应用程序的ionic 2脱机数据同步抛出类型错误:无法读取属性';openDatabase';未定义的,sqlite,cordova,ionic-framework,ionic2,azure-mobile-services,Sqlite,Cordova,Ionic Framework,Ionic2,Azure Mobile Services,我已经使用visual studio模板创建了ionic 2应用程序,并尝试在Azure移动应用程序功能中开发脱机数据同步。 我已经安装了节点“azure移动应用程序客户端模块”和 从“azure移动应用程序客户端”使用asimport*作为WindowsAzure在app.components.ts中并使用初始化存储 Client=新的WindowsAzure.MobileServiceClient(“url”)但将我显示为“TypeError:无法读取未定义的属性“openDatabase”
import*作为WindowsAzure代码>在app.components.ts中并使用初始化存储
Client=新的WindowsAzure.MobileServiceClient(“url”)代码>但将我显示为“TypeError:无法读取未定义的属性“openDatabase”时出错
我还安装了@ionic native/sqlite节点模块和cordova sqlite存储插件
请参阅以下代码:
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { NavController } from 'ionic-angular';
//declare var WindowsAzure: any;
import * as WindowsAzure from 'azure-mobile-apps-client';
var mobileAppClient, // Connection to the Azure Mobile App backend
store, // Sqlite store to use for offline data sync
syncContext, // Offline data sync context
tableName
var useOfflineSync: boolean = true;
@Component({
selector: 'page-about',
templateUrl: 'about.html'
})
export class AboutPage {
constructor(public navCtrl: NavController, public platform:Platform) {
platform.ready().then(() => {
mobileAppClient = new WindowsAzure.MobileServiceClient("https://myapp.azurewebsites.net");
// Create the sqlite store
store = new WindowsAzure.MobileServiceSqliteStore('store.db');
store.defineTable({
name: 'todoitem',
columnDefinitions: {
id: 'string',
text: 'string',
complete: 'boolean',
version: 'string'
}
});
// Get the sync context from the client
syncContext = mobileAppClient.getSyncContext();
// Initialize the sync context with the store\
syncContext.initialize(store).then((syc) => {
// Get the local table reference.
tableName = mobileAppClient.getSyncTable('todoitem');
// Sync local store to Azure table when app loads, or when login complete.
syncContext.push().then((res) => {
// Push completed
// Pull items from the Azure table after syncing to Azure.
syncContext.pull(new WindowsAzure.Query('todoitem')).then((data) => {
alert(JSON.stringify(data));
}, (err) => {
alert(err);
});
});
}, function (err) {
alert(err);
});
});
}
}
这可能是因为客户端数据库表列与远程数据库不匹配。请注意,通过迁移删除列不会删除SQLite中的列。您是从web浏览器还是物理设备进行测试的?@AaronChen我已经在android emulator上进行了测试。您使用的是js库还是cordova插件@SurajRao I添加了“azure移动应用程序客户端”节点模块和“cordova插件ms azure移动应用程序”cordova插件。还添加了相关插件,如“cordova sqlite存储”和“cordova plugin inappbrowser”。使用一个就足够了。我记得,如果我使用命令行创建项目。然后它就正常工作了。我只有在使用VS ionic模板创建时才面临这个问题。