好的,我跟着how-to-return-the-response-from-an-asynchronous-call
无论我无法更新变量标签..如何更新标签
function foo() {
// RETURN the promise
return fetch("stack-url").then(function(response){
return response.json(); // process it inside the `then`
});
}
self.addEventListener('push', function(event){
var title = 'Featured Message';
var body = 'StackOverFlow Question Got Featured Post';
var tag = 'this-is-dummy-tag';
foo().then(function(response){
console.log('this is then result ', response);
var tag = response.question_id;
return tag;
// access the value inside the `then`
})
event.waitUntil(
self.registration.showNotification(title, {
body:body,
tag:tag,
})
);
});
答案 0 :(得分:0)
尝试包含event.waitUntil
秒.then()
个链接,使用第一个tag
的返回值设置.then()
;或者首先设置tag
;在,
对象
event.waitUntil
foo().then(function(response){
console.log('this is then result ', response);
var tag = response.question_id;
return tag;
// access the value inside the `then`
})
.then(function(data) {
event.waitUntil(
self.registration.showNotification(title, {
body:body,
tag:data
})
);
})
foo().then(function(response){
console.log('this is then result ', response);
var tag = response.question_id;
// access the value inside the `then`
event.waitUntil(
self.registration.showNotification(title, {
body:body,
tag:tag
})
);
})