本文整理汇总了TypeScript中ionic-framework/ionic.SqlStorage类的典型用法代码示例。如果您正苦于以下问题:TypeScript SqlStorage类的具体用法?TypeScript SqlStorage怎么用?TypeScript SqlStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SqlStorage类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: removeClicker
public removeClicker(id: string): void {
// remove clicker from the service
this.clickers = this.clickers.filter((clicker: Clicker) => { return clicker.getId() !== id; });
// remove from ids array
this.ids = this.ids.filter((filterId: string) => { return filterId !== id; });
// null id in db
this.storage.remove(id);
// update service's ids array
this.storage.set('ids', JSON.stringify(this.ids));
}
示例2: newClicker
public newClicker(name: string): string {
const id: string = this.uid();
const clicker: Clicker = new Clicker(id, name);
// add the clicker to the service
this.clickers.push(clicker);
// add the id to the service (need to keep a separate reference of IDs so we can cold load clickers)
this.ids.push(id);
// save the clicker by id
this.storage.set(id, JSON.stringify(clicker));
// save the service's ids array
this.storage.set('ids', JSON.stringify(this.ids));
return id;
}
示例3: newTask
public newTask(name: string): string {
const id: string = this.uid();
// by default time is set to 300
const task: Task = new Task(id, name, 300);
// add the task to the service
this.tasks.push(task);
// add the id to the service (need to keep a separate reference of IDs so we can cold load clickers)
this.ids.push(id);
// save the clicker by id
this.storage.set(id, JSON.stringify(task));
// save the service's ids array
this.storage.set('ids', JSON.stringify(this.ids));
return id;
}
示例4: Promise
return new Promise((resolve: Function) => {
let ids: Array<string> = [];
this.storage.get('ids') // return the promise so we can chain initClickers
.then((rawIds: string) => {
// ids are stored as stringified JSON array
ids = JSON.parse(rawIds) || [];
})
.then(() => resolve(ids));
});
示例5: Promise
return new Promise((resolve: Function) => {
let tasks: Array<Task> = [];
for (let id of ids) {
this.storage.get(id)
.then((task: string) => {
tasks.push(this.initTask(task));
});
}
resolve(tasks);
});
示例6: doClick
public doClick(id: string): void {
const clicker: Clicker = this.getClicker(id);
clicker.doClick();
// save the clicker with updated click in storage
this.storage.set(clicker.getId(), JSON.stringify(clicker));
}