2016-01-20 45 views
0

我对MEAN堆栈非常陌生,我一直试图保存一个复选框值的数组,并尝试从mongodb中检索它。我已经明确定义了有关使用猫鼬的嵌入式数组的模式问题是如何将选中的项插入到mongodb中。 我的表单代码是这样:在MEAN应用程序中处理复选框

<table class="table"> 
<tr> 
    <th><span>Project Name :</span></th> 
    <th><input type="text" ng-model="project.projectName" placeholder="Enter projectname"></th> 
</tr> 
<tr> 
    <th>Base Url:</th> 
    <th><input type="text" ng-model="project.baseUrl" placeholder="Enter Base URL"></th> 
</tr> 
<tr> 
    <th>Choose APIs:</th> 
</tr> 
<tr> 
    <th><input type="radio" ng-model="project.api" value="downloading" ng-change="downloadAPI()"><span>Downloading API</span></th> 
    <th><input type="radio" ng-model="project.api" value="scraping" ng-change="scrapAPI()"><span>Scraping API</span></th> 
    <th><input type="radio" ng-model="project.api" value="comparision" ng-change="compareAPI()"><span>Comparision API</span></th> 

    <tbody ng-show = "project.api=='downloading'" ng-hide="!downloading"> 
<tr> 
    <th>Choose Files:</th> 
</tr> 
<tr> 
<th><input type="checkbox" ng-model=project.js><span>Js</span></th> 
<th><input type="checkbox" ng-model=project.css> <span>Css</span></th> 
<th><input type="checkbox" ng-model=project.images><span>Images</span></th> 
<th><input type="checkbox" ng-model=project.fonts><span>Fonts</span></th> 
<th><input type="checkbox" ng-model=project.multimedia><span>Multimedia</span></th> 
</tr> 
</tbody> 
<tr> 
    <th><input type="checkbox" ng-model="project.run" ng-change="runproject()"><span>Run as soon as project is completed!</span></th> 
</tr> 

<tr> 
    <th> 
    <div ng-show="action === 'add'"><span><button class="btn btn-success" ng-click="save()">Add Project</button></span></div> 
    <div ng-show="action === 'edit'"><span><button class="btn btn-success" ng-click="modify()">Update</button></span> 
    </div> 

    </th> 
</tr> 

每一件事情是罚款与控制器和服务器中的我的岗位要求是这样:

//post request 
router.post('/',function(req,res,next){ 
var files=[]; 
if(req.body.js != null){ 
files.push(req.body.js); 
} 

    if(req.body.css != null){ 
    files.push(req.body.css); 
} 

    if(req.body.images != null){ 
    files.push(req.body.images); 
    } 

    if(req.body.fonts != null){ 
    files.push(req.body.fonts); 
    } 
    console.log(files); 
    var obj= new project(req.body);// new object of the mongoose model 

    obj.save(function(err,result){ 
    if(err){ 
     console.log(err); 
    } 
    res.json(result); 

}); });

是否有任何其他方式将复选框的值存储在数据库中?我非常感谢你的时间和建议,这对我来说真的意义重大。

回答

0

你逝去从前端数据使用方法

= NG单击“修改(项目)”

数据验证部也客户side.Use角度做需要胜任检查空输入。如果使用该输入,则不需要检查数据为空。

files.push(req.body)