我已经完成了一个角度流星应用程序,其中我的settings.html中列出了与复选框一起列出的类别。选中它后,它将显示在dashboard.html中。也就是说,设置集合中的数组被推送到用户的集合中。但是现在当我尝试取消检查时,它再次被推送到用户的收藏中。所以告诉我如何在取消选中时将其删除。
这是我的settings.html页面
<div layout-gt-sm="row" ng-repeat="detail in dynamicSettingsCtrl.generalSettings.generalSetting">
<md-checkbox aria-label="Checkbox 1" ng-model="dynamicSettingsCtrl.status[detail._id]" ng-change="dynamicSettingsCtrl.getClicked(detail._id)">
<p> {{detail.name}} {{ detail.data.cb1 }}</p>
</md-checkbox>
</div>
这是我的客户端js for settings.html
let self = this;
let user = Meteor.user();
let userId = Meteor.userId();
self.data = {};
self.data.cb1 = true;
self.isChecked = true;
CurrentPage.setTitle('Settings');
let customerId = [userId]
self.subscribe('getCustomerDetails', () => [customerId], {
onReady: function() {
self.helpers({
currentUser: () => {
return Meteor.users.findOne({
_id: Meteor.userId()
});
}
})
}
});
self.subscribe('generalSettingsDetails', () => [])
this.status = {}
self.autorun(() => {
this.currentUser =
Meteor.users.findOne({
_id: Meteor.userId()
});
this.generalSettings = {}
this.generalSettings['generalSetting'] = GeneralSettings.find({}).fetch()
var selectedObs = []
console.log(self.currentUser.settings)
console.log(this.generalSettings)
_.map(this.generalSettings['generalSetting'], function(genset) {
delete genset.$$hashKey
if (self.currentUser) {
let ret = _.find(self.currentUser.settings, function(sets) {
return sets._id === genset._id
})
if(ret){
self.status[ret._id] = true
}
}
})
})
// console.log(self.currentUser)
///subscribing general 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
// };
// }
// })
// }
// });
///end of subscribing general settings and starting of click function
self.getClicked = (settingId) => {
self.dataArry = {};
self.dataChk = {};
// self.currentUser = {};
console.log(settingId)
Meteor.call("updateSettings", settingId, function(error, result) {
if (error) {
ToastService.getToastbox($mdToast, 'Something went error!Unable to add details', 'error-toast');
} else {
//self.currentUser = {};
ToastService.getToastbox($mdToast, 'Details added successfully !', 'success-toast');
}
});
}
这是我的服务器端js for settings.html
updateSettings: function(generalValue) {
let userId = Meteor.userId();
let settingsDetails = GeneralSettings.findOne({
"_id": generalValue
});
Meteor.users.update({
_id: userId
}, {
$push: {
"settings": {
"_id": generalValue,
"name": settingsDetails.name,
"description": settingsDetails.description,
"tag": settingsDetails.tag,
"type": settingsDetails.type,
"status": settingsDetails.status
}
}
})
}
如何删除?如何在取消选中时删除该勾选
答案 0 :(得分:0)
现在,您在复选框上的每个更改上调用相同的函数(仅按其ID查找)。它调用相同的更新方法,并且您没有限制未选中或已检查条件的方法。
当checked为true时,仅调用getClicked函数,否则返回false。