处理 MEAN 应用程序中的复选框
Handling checkboxes in MEAN application
我是 MEAN 堆栈的新手,我一直在尝试保存复选框值数组并尝试从 mongodb 检索它。我已经明确定义了有关使用猫鼬的嵌入式数组的模式,问题是如何在 mongodb 中插入选中的项目。我的表单代码如下所示:
<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 请求如下所示:
//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);
});});
有没有其他方法可以在数据库中存储复选框值?我非常感谢您的时间和建议,这对我来说真的意义重大。
当您从前端传递数据时,请使用该方法
ng-click="modify(project)"
数据验证部分也在客户端进行。使用角度所需的能力检查零输入。如果您使用它,则不需要检查数据是否为空。
files.push(req.body)
相关文章:
- 如何保持引导程序下拉复选框列表下拉
- 应用程序脚本-拆分谷歌表单复选框用逗号回答
- 购物清单应用程序:使用复选框划掉项目
- Rally自定义应用程序复选框筛选器不工作
- 如何为动态创建的复选框和自定义验证程序应用自定义验证
- 如何在 MVC 应用程序中单击标签时选中所有复选框
- PHP 复选框邮件程序为每个错误
- 处理 MEAN 应用程序中的复选框
- 不加载简单的复选框绘图程序
- 访问rails应用程序中的post方法后的复选框行为
- 添加类“;copyMe”;和enable按钮,对复选框应用相同的行为
- 如何为第一次选择和第二次选择复选框应用不同的颜色
- Angularjs应用程序中文本框和复选框模型中触发跨度点击和观看事件序列时发生冲突
- 与上述ASP Web应用程序中的复选框选项相同
- 在rails应用程序中禁用复选框输入
- 如何使用Titanium Appcelerator在应用程序中创建一个复选框首选项区域
- 分组复选框在谷歌应用程序脚本绑定到谷歌表格
- 如何在循环中有复选框的情况下对多个复选框应用验证
- 当我选中复选框时,如何在我的待办事项应用程序中删除相应复选框的文本
- 表示单页应用程序的用户配置状态(复选框、选择列表)的标准做法