在角度流星中更新db时,选中复选框

时间:2016-04-19 07:32:15

标签: angularjs mongodb meteor typescript angular-meteor

我正在使用复选框列出设置集合中的一些菜单。 like this

当我检查一个菜单时,它会被推送到具有该菜单ID的用户集合中。

但是当我导航到其他页面或刷新页面时,选中的复选框将自动取消选中。我想避免这种情况。

此处菜单从设置集合中列出,但是从用户集合中检查已检查的条件,无论菜单是否被推送。

我的设置集如下所示:

{
    "_id" : "GdfaHPoT5FXW78aw5",
    "name" : "URL",
    "description" : "https://docs.mongodb.org/manual/reference/method/db.collection.update/",
    "type" : "url",
    "tag" : "This is a demo of an Url selected",
    "status" : false
}

我的用户集合如下:

"settings" : [ 
    {
        "_id" : "GdfaHPoT5FXW78api",
        "name" : "Image",
        "description" : "uploads/images-ihDszYA8xqHSGfBo5-prof.jpg",
        "tag" : "This is a demo for an image",
        "type" : "image",
        "status" : false
    }, 
    {
        "_id" : "GdfaHPoT5FXW78aw5",
        "name" : "URL",
        "description" : "https://docs.mongodb.org/manual/reference/method/db.collection.update/",
        "tag" : "This is a demo of an Url selected",
        "type" : "url",
        "status" : true
    }]

我的HTML是这样的:

  <div layout-gt-sm="row"  ng-repeat="detail in settingCtrl.generalSettings">
        <md-checkbox aria-label="Checkbox 1"  ng-model="detail.status" ng-change="dynamicSettingsCtrl.getClicked(detail._id)">

               <p> {{detail.name}} {{ detail.data.cb1 }}</p>
        </md-checkbox>
    </div>

这是我的客户端js:

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:

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 个答案:

没有答案