我正在尝试使用on。(“trigger”)方法更改本地通知中的数据。但是,它会使用相同的数据一次又一次地显示相同的通知。通过这种方式,我知道通知正在发挥作用,但它并没有改变触发器上的数据。
Ionic Framework: 3.1.1
Node: 6.10.0
OS: Windows 7
Ionic CLI: 3.0.0
Cordova CLI: 7.0.1
我正在使用以下代码进行触发:
ionViewDidLoad() {
// Get the JSON data from our itemApi
this.itemApi.getItems().then(data => {
this.items = data;
let randomNumber = Math.floor(Math.random() * this.items.length)
// Select the random object an pass it to the oneItem object
this.oneItem = this.items[randomNumber];
});
// --------------------------------------------------------------------------------------
// ---- Function for changing data on trigger
// --------------------------------------------------------------------------------------
// Creates a callback function on the schedule trigger - populates the notification with new data
this.localNotifications.on("trigger", function() {
// Get the JSON data from our itemApi
this.itemApi.getItems().then(data => {
this.items = data;
let randomNumber = Math.floor(Math.random() * this.items.length)
// Select the random object an pass it to the oneItem object
this.oneItem = this.items[randomNumber];
// The notification
let notification = {
id:1,
title: this.oneItem.word,
text: this.oneItem.description,
every: "minute"
};
this.notifications.push(notification);
this.notifications.update(this.notifications);
});
});
}
你知道它为什么不起作用吗?