【发布时间】:2016-02-22 03:15:26
【问题描述】:
由于某些奇怪的原因,我根本无法在本地复制,刷新页面时流星不会加载任何集合,但它们在从状态到状态的转换时工作得很好。我在集合中添加了一个 onready 和 onerror 函数,但它们都没有真正在刷新时运行。
this previous so question seems to solve the problem. 我无法像他那样解决问题,因为显然 Angular 的 ui 路由器不尊重 waiton 和数据。因此,该链接对我来说并没有多大用处。几天来我一直在尝试解决这个问题,但我一无所获。提前感谢您的帮助。
我确定我在这里发布了太多代码,但我宁愿全面。
collections/meetings.js
Meetings = new Mongo.Collection('meetings');
Meetings.allow({
insert: function (userId, doc) {
return userId && doc.owner === userId;
},
update: function (userId, doc, fields, modifier) {
return userId && doc.owner === userId;
},
remove: function (userId, doc) {
return userId && doc.owner === userId;
}
});
Meetings.before.insert(function(userId, doc) {
doc.created_at = new Date().getTime();
doc.owner = userId;
doc.private = true;
});
Meetings.before.update(function(userId, doc, fieldNames, modifier, options) {
modifier.$set = modifier.$set || {};
modifier.$set.updatedAt = new Date().getTime();
});
发布/会议.js
Meteor.publish("meetings", function () {
return Meetings.find({});
});
meetingController.js
function meetingCtrl($scope, $location, $reactive, $http) {
const vm = this;
vm.me = Meteor.userId();
vm.lastWeek = moment().add(-1, 'weeks').unix();
$reactive(vm).attach($scope);
vm.subscribe('meetings', () => [], {
onReady: function () { console.log("onReady", arguments); },
onError: function () { console.log("onError", arguments); }
});
vm.helpers({
meetings: () => Meetings.find(
{$and: [
{created_at: {$gte: this.getReactively('lastWeek')}},
{owner: this.getReactively('me')}
]})
});
index.ng.html
<div ng-repeat="meeting in vm.meetings" class="meeting">
{{meeting.name}}
</div>
路由器.js
.state('meetings', {
url: '/meetings',
controller: 'meetingCtrl',
controllerAs: 'vm',
templateUrl: baseUrl + 'meetings/' + template,
resolve: {
user: ($auth) => {
return $auth.requireUser();
}
}
})
【问题讨论】:
标签: javascript angularjs meteor angular-meteor