Как зарегистрировать суп SmartStore в Ionic App?
Я построил базовое гибридное приложение с сайдмену в Inonic V2. Я использую код ниже, чтобы получить многоуровневые значения меню из статического JSON
Поставщики / data-service / data-service.ts: getMainMenu ()
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';
/*
Generated class for the DataServiceProvider provider.
See https://angular.io/guide/dependency-injection for more info on providers
and Angular DI.
*/
@Injectable()
export class DataServiceProvider {
constructor(public http: Http) {
console.log('Hello DataServiceProvider Provider');
}
getMainMenu(){
return this.http.get('assets/data/mainmenu.json')
.map((response:Response)=>response.json().Categories);
}
}
src / app / app.component.ts: getMainMenu () в конструкторе
import { Component, ViewChild } from '@angular/core';
import { Nav, Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list';
import { DataServiceProvider } from '../providers/data-service/data-service'
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = HomePage;
pages: any[]; //Array<{title: string, component: any}>;
mainmenu: any[];
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, public dataService: DataServiceProvider) {
this.initializeApp();
this.dataService.getMainMenu().subscribe((Response)=>{
this.mainmenu = Response;
console.log(this.mainmenu);
});
// used for an example of ngFor and navigation
this.pages = [
{ title: 'Home', component: HomePage },
{ title: 'List', component: ListPage }
];
}
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
openPage(page) {
// Reset the content nav to have just this page
// we wouldn't want the back button to show in this scenario
this.nav.setRoot(page.component);
}
toggleSection(i) {
this.mainmenu[i].open = !this.mainmenu[i].open;
};
toggleItem(i,j) {
this.mainmenu[i].SubCategories[j].open = !this.mainmenu[i].SubCategories[j].open;
};
}
Теперь вместо JSON я планирую получить значения меню из локальной базы данных мобильного телефона - Salesforce SmartStore
где данные хранятся в soups
, чтобы включить автономную работу.
Я добавил Mobile SDK plugin
к приложению, и я считаю, что следующим шагом является register the Soup
создать модель данных, где мне нужна помощь.
Здесь и во многих местах я нашел только код Javascript для register Soup in SmartStore
, Могу ли я получить некоторую помощь о том, как зарегистрировать суп SmartStore в моем Ionic в AngularJS? Я родом из C++, и это мой первый опыт работы с мобильными приложениями.
Поскольку меню должно быть готово к моменту запуска приложения, я полагаю, что это должно быть сделано путем замены HTTP Get
метод в data-service.ts -> getmainmenu()
, Или, если настройка модели данных - однократный процесс, следует ли это делать вне приложения? Я ищу помощь для подтверждения подхода и помощи с синтаксисом