带sqlite的Ionic3-选择 [英] Ionic3 with sqlite- on select

查看:114
本文介绍了带sqlite的Ionic3-选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Android中的cordova从SQL Lite DB查询记录时遇到了问题

I have issue with querying the records from SQL Lite DB using cordova in Android

this.platform.ready().then(() => {
          this.sqlite.create({
            name: 'temp.db',
            location: 'default'
          }).then((db: SQLiteObject) => {

           console.log('Querying for temp user '+user.userName+'Password '+user.password);

           console.log('User queried'+user.userName);

            db.executeSql("SELECT * FROM USER  where USER_NAME = ? and USER_PWD=?", [user.userName,password]).then(
            response  => {
              let records='';
              for (let i = 0; i < response.rows.length; i++) {
                records = records+ JSON.stringify(response.rows.item(i))+'\n'; //Prints row correctly
              }
             this._util.presentAlert('Records selected like from- USR-',records);
            })
         .catch(
            e => this._util.presentAlert('Fail- Select like from- USER-Temp DBUSER',e));

            db.executeSql("SELECT * FROM USER  where USER_NAME = ? and USER_PWD=? ", [user.userName,password ]).then(
               response => {
                if (response && response.rows && response.rows.length > 0) {


                    for (let i = 0; i < response.rows.length; i++) {
                            let access = { 
                                firstName :response.rows.item[i].FIRST_NAME, //This is undefined.
                                lastName :response.rows.item[i].LAST_NAME,
                                userName:response.rows.item[i].USER_NAME,
                                userId:response.rows.item[i].USER_ID
                              }

                             observer.next(access);

                      }

                      observer.complete();

                } else {
                  let access = {status:'Fail',msg:'Bad credentials for Temp DB login'};
                 console.log('No record for the user from- USER'+user.userName);
                  observer.next(access);
                  observer.complete();               

                }
              })
              .catch(
              e => {
               console.log('Fail- Select query gone wrong * from- USER FOR Temp DB LOGIN' + e);
                let access = {status:'Fail',msg:'Bad credentials for Temp DB login'};
                observer.next(access);
                observer.complete();

              });

问题是这是正确打印记录

The issue is this one is printing the records correctly

JSON.stringify(response.rows.item(i))
O/P
{'USER_ID':1,'FIRST_NAME':'Temp','LAST_NAME':'User','USER_NAME':'TEMPUSER','USER_PWD':'TEMPPWD'}

以下引发未定义的错误

firstName :response.rows.item[i].FIRST_NAME
Fail- Select query gone wrong * from- USER FOR Temp DB LOGIN TypeError: Cannot read property 'FIRST_NAME' of undefined



的属性 FIRST_NAME

为什么我无法以JSON的形式获取它?

Why am I unable to fetch it as as JSON?

推荐答案

我不知道它有多晚了,但是您必须使用:

I don´t know how late it is, but you must use:

response.rows.item(i).FIRST_NAME

()而不是[]。

这篇关于带sqlite的Ionic3-选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆