2017-05-09 40 views
0

我已创建登录屏幕和主屏幕我有三个数据的对象,必须使用SQLite如何做到这一点我没有得到任何想法离子3:如何使用存储(SQLite的)插件

{ 
     "userId": "", 
     "loginId": "", 
     "passwd": "" 
    } 
存储

在我的店里的SQLite代码都

export class SqlStorage { 

    constructor(public http: Http,private sqlite: SQLite) { 
    console.log('Hello SqlStorage Provider'); 

    this.sqlite.create({ 
     name: 'data.db', 
     location: 'default' 
    }) 
    .then((db: SQLiteObject) => { 
     db.executeSql('create table kmartIndia(name VARCHAR(32))', {}) 
     .then((db) => { 
     console.log('Executed SQL'); 
     }) 
     .catch((e) => { 
     console.log(e) 
     }); 
    }) 
    .catch((e) => { 
     console.log(e) 
    }); 
    } 

    setValue(){} 

    getValue(){} 

    removeValue(){} 
} 

我不知道如何使它工作

如何创建一个TA我已经创建了一个供应商ble以及如何设置,获取和删除这个值,我对这个任何帮助都不是很熟悉。

+0

@mayur我看到一个我无法理解它在哪里创建以及如何将该对象设置到表中 –

+0

http://stackoverflow.com/questions/40277905/how-to-use-sqlite- with-ionic-2-rc-0在这里你是,c哎哟,thx! – mosca90

+0

@ mosca90我不理解你的第6点 –

回答

0

一些挖掘后,我发现如何使这项工作。

看来“创建”方法用于创建和打开数据库。

在YOUT的setValue()做的事:

this.sqlite.create({ 
    name: 'data.db', 
    location: 'default' 
}).then((db: SQLiteObject) => { 
    db.executeSql("insert into kmartIndia(name) values ('Mohan')", {}).then(() => yourVariable = 'Executed SQL').catch(e => yourVariable = e); 
}).catch(e => console.log(e)); 

而且,从表中获取数据:

this.sqlite.create(
    {name: 'data.db', location: 'default'} 
).then(
    (db: SQLiteObject) => { 
     db.executeSql('select * from kmartIndia', {}).then( 
     (data) => { 
      for(var i =0; i< data.rows.length;i++){ 
      yourVariable += data.rows.item(i).name 
      } 
     } 
    ) 
    } 
); 

(我赋值用+ =,但它只是和例子:) )