har*_*nat 5 sqlite cordova azure-mobile-services ionic-framework ionic2
我使用visual studio模板创建了ionic 2 app,并试图在Azure Mobile Apps功能中开发离线数据同步.我已经安装了节点"azure-mobile-apps-client模块",并import * as WindowsAzure from 'azure-mobile-apps-client';在app.components.ts中使用,并使用初始化存储
Client = new WindowsAzure.MobileServiceClient("url");但错误显示我为"TypeError:无法读取未定义的属性'openDatabase'".
我还安装了@ ionic-native/sqlite节点模块和cordova-sqlite-storage插件.
请看下面的代码:
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);
});
});
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
356 次 |
| 最近记录: |