0

I used MacOS 10.13 and my ionic info CLI packages:

(/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

Global packages:

cordova (Cordova CLI) : 8.0.0 

Local packages:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : android 6.3.0
Ionic Framework    : ionic-angular 3.9.2

System:

Node : v8.11.0
npm  : 5.6.0 
OS   : macOS High Sierra

Environment Variables:

ANDROID_HOME : not set

Misc:

backend : pro

mycode.ts

this.storage.get('waitmsg').then((waitmsg) => {
    if (waitmsg != null) {
        this.http.post(link, data, httpOptions)
          .subscribe(data => {
            this.storage.ready().then(() => {
                var msglist = {}
                for(var msg in waitmsg) {
                    var receiveuser = waitmsg[msg]['receiveuser']
                    var mypk = waitmsg[msg]['userpk']
                    var content = waitmsg[msg]['content']
                    let setmsg = {
                        userpk: mypk,
                        receiveuser: receiveuser,
                        content: content,
                        createDate: new Date(),
                        read: 1
                    }
                    this.storage.get(receiveuser + ":" + mypk).then((data) => {
                        data.push(setmsg)
                        this.storage.set(receiveuser + ":" + mypk, data)
                    });
                }
                this.storage.remove('waitmsg')
            });
        }, error => {
            alert("error")
        });
    }
});

waitmsg

[{'userpk': '11', 'receiveuser': '9', 'content': '1'}, 
 {'userpk': '11', 'receiveuser': '9', 'content': '2'}, 
 {'userpk': '11', 'receiveuser': '9', 'content': '3'}, 
 {'userpk': '11', 'receiveuser': '3', 'content': '4'},
 {'userpk': '11', 'receiveuser': '3', 'content': '5'},
 {'userpk': '11', 'receiveuser': '9', 'content': '6'}, 
 {'userpk':'11', 'receiveuser': '3', 'content': '7'}]

I tested this code. this.storage.get is run once at least. I want it to run all the time, how can I acheve this?

Paul
  • 4,160
  • 3
  • 30
  • 56
Adam
  • 325
  • 1
  • 4
  • 20

0 Answers0