2017-05-09 43 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 
      } 
     } 
    ) 
    } 
); 

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