![](/img/trans.png)
[英]kendo grid loaded before dom is ready in partial views in mvc with angular routing
[英]How to ensure meteor local collection is ready before routing
我正在使用Meteor + AngularJS框架。
我想根据离线集合中存储的数据来控制路由(使用ground:db),但是不能保证离线数据在路由之前已经准备好。
如果集合不是脱机的,则似乎有一些值得研究的方法,例如“ waitOn”或“ subscriptionReady”,但脱机集合不需要订阅或发布,如何在路由或启动应用程序之前确保它们已准备就绪? ?
关键源片段:
1.route.js
import { LastLogin } from '../lib/collections';
angular.module('app')
.config(function ($stateProvider, $urlRouterProvider) {
console.log(LastLogin.find().count());
if(LastLogin.find().count() > 0){
$urlRouterProvider.otherwise('main/homepage');
}else{
$urlRouterProvider.otherwise('login');
}
});
2.collections.js
export const LastLogin = new Ground.Collection('lastLogin', {connection: null});
在大多数情况下,LastLogin.find()。count()为0,很少为1,实际上lastLogin集合中有几条记录可以在显示登录页面后正确打印出来,对于我。
我尝试通过Tracker.autorun封闭以下代码
Tracker.autorun(function(){
if(LastLogin.find().count() > 0){
$urlRouterProvider.otherwise('main/home');
}else{
$urlRouterProvider.otherwise('login');
}
});
但没有帮助。
我的最终目的是使最后一个用户即使在脱机状态下也自动登录。 有更好的解决方案吗?
最终我自己解决了。 这个想法是地面的:db有一个“已加载”事件,该事件在这里记录: https : //github.com/GroundMeteor/db/blob/grounddb-caching-2016/EVENTS.md ,我几天前看过这个文档,但是没有马上猜出用法。
来源(app.js):
// Startup
if (Meteor.isCordova) {
angular.element(document).on('deviceready', onReady);
}else {
angular.element(document).ready(onReady);
}
function onReady() {
Ground.on('loaded', function (ret) {
if(ret.collection == 'lastLogin'){
angular.bootstrap(document, ['app']);
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.