gpt4 book ai didi

javascript - Meteor:在发布中使用 Meteor._sleepForMs() 时 Iron router 不显示加载模板

转载 作者:行者123 更新时间:2023-11-30 16:39:24 29 4
gpt4 key购买 nike

我是 Meteor 的新手,遇到一个问题,即 iron router 在“waitOn”函数期间没有显示我的加载模板。

我正在使用 Meteor._sleepForMs(2000) 模拟页面发布中的网络延迟。延迟很明显,但在页面加载之前我只是得到一个空白模板。我的印象是加载模板会一直显示到“waitOn”完成(但也许这是不正确的?)。

我的加载模板(当我直接在页面上调用模板 {{> loading}} 时显示正常):

<template name="loading">
{{> spinner}}
</template>

我的路由器代码:

Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading'
});


Router.route('/editor/:_id',{
//route template
name: 'editorProfile',
//subscription to userProfile publication of editor
waitOn: function(){
Meteor.subscribe('userProfile',this.params._id);
},
//data context is the user
data: function(){
return Meteor.users.findOne(this.params._id);
}
});

和我的“userProfile”出版物:

Meteor.publish('userProfile', function(_id){

Meteor._sleepForMs(2000);//simulate network lag

//find the user by id
var user=Meteor.users.findOne(_id);

//if not found, mark subscription ready and quit
if (!user){
this.ready();
return;
}
//if user is the currently logged in user
if (this.userId==user._id){
//return the full user document
return Meteor.users.find(this.userId);
}
//if viewing another user
else {
//only return the user's profile
return Meteor.users.find({'_id': user._id},
{fields: {
profile: 1
}
});
}
});

最佳答案

确保在调用 waitOn 时返回订阅

waitOn: function(){
return Meteor.subscribe('userProfile',this.params._id);
}

关于javascript - Meteor:在发布中使用 Meteor._sleepForMs() 时 Iron router 不显示加载模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32231266/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com