离子 2 使用 Azure 移动应用进行脱机数据同步引发类型错误:无法读取未定义的属性'openDatabase'



我已经使用Visual Studio Template创建了Ionic 2应用程序,并尝试在Azure Mobile Apps功能中开发离线数据同步。我已经安装了节点" Azure-Mobile-apps-client的模块",并且在app.components.ts中使用AS as as import * as WindowsAzure from 'azure-mobile-apps-client';,并使用 Client = new WindowsAzure.MobileServiceClient("url");但是错误显示我为" TypeError:无法读取属性'opendatabase'of Undefined'。

我还安装了 @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中的列。

相关内容

最新更新