我为设置创建了一个角度流星页面。在该设置中,列出了页面菜单,当选择菜单时,它将显示在主页中。取消选中后,它将从仪表板中删除。代码是
在客户端js`angular.module('demo')。directive('generalSettings',function(){
return {
restrict: 'E',
templateUrl: 'client/lms/general-settings.html',
controllerAs: 'generalSettingsCtrl',
controller: function($scope, $reactive, $stateParams, $mdDialog, $state, $mdToast, ToastService, $timeout, $q, $log, errorValidatorUtil, CurrentPage) {
$reactive(this).attach($scope)
let self = this;
let user = Meteor.user();
let userId = Meteor.userId();
let customerId = [userId]
self.subscribe('getCustomerDetails', () => [customerId], {
onReady: function() {
self.helpers({
currentUser: () => {
return Meteor.users.findOne({
_id: Meteor.userId()
});
}
})
}
});
// console.log(Meteor.users.findOne({
// _id: Meteor.userId()
// }))
self.data = {};
self.data.cb1 = true;
self.isChecked = true;
CurrentPage.setTitle('Settings');
self.subscribe('generalSettingsDetails', () => [], {
onReady: function() {
self.helpers({ /// helpers to make it reactive
generalSettings: () => {
let settings = GeneralSettings.find({}).fetch()
//var subSettings = []
for (key in settings) {
delete settings[key].$$hashKey
}
console.log(settings)
return {
'generalSetting': settings
};
}
})
}
});
self.getClicked = (dynamicSetting, settingId, detail) => {
self.dataArry = {};
self.dataChk = {};
self.generalSetting = {};
console.log(self.generalSettings.generalSetting)
Meteor.call("updateStatus", detail, function(error, result) {
if (error) {
ToastService.getToastbox($mdToast, 'Something went error!Unable to add details', 'error-toast');
} else {
self.generalSetting = {};
ToastService.getToastbox($mdToast, 'Details added successfully !', 'success-toast');
}
});
}
}
}
}) 服务器js就像`Meteor.methods({ updateStatus:function(settings,status){ 让_ids = [] 执行console.log(设置) if(settings。$$ hashKey) 删除设置。$$ hashKey
GeneralSettings.update({
_id: settings._id
}, {
$set: {
"status": settings.status
}
}, {
"multi": true
})
}
})
和html就像
<div layout="column" layout-wrap layout-padding layout-fill class="littleWhiteFrame" ng-cloak>
<div>
<div layout="row" class="requestDetailElems">
<h4 class="md-subhead" layout-marginSettings> Settings</h4>
<span flex></span>
</div>
</div>
<md-divider></md-divider>
<div layout="row">
<fieldset class="standard">
<div layout-gt-sm="row" ng-repeat="detail in generalSettingsCtrl.generalSettings.generalSetting">
<md-checkbox aria-label="Checkbox 1" ng-model="detail.status" ng-change="generalSettingsCtrl.getClicked(generalSettingsCtrl.detail[$index],currentUser._id,detail)">
<p> {{detail.name}} {{ detail.data.cb1 }}</p>
</md-checkbox>
</div>
</fieldset>
</div>
我有一个mongo集合,用于设置id,name,description,tag,status等字段。
当选择菜单时,状态将变为true。
现在我想对此代码进行一些更改,我想为不同的用户制作不同的菜单。所以在用户集合中我必须按下所选菜单。 例如:user1,user2如果user1选择home,则从设置然后在他的仪表板主页中关于我们,并且应该查看aboutus。如果用户2选择家庭和推荐,那么当他登录回家并且推荐书应该被视为不在家和关于
答案 0 :(得分:0)
您可以创建单独的菜单栏并使用ng-if显示它们。
答案 1 :(得分:0)
您只需将设置集合推送到用户集合。您可以根据用户ID获取数据。
Meteor.users.update(
{_id:userId}, {“$ push”:{“settings”:settingDetails}} )