【问题标题】:Angularjs, ng-click, how put array of checkbox in MongoDBAngularjs,ng-click,如何在 MongoDB 中放置复选框数组
【发布时间】:2016-02-03 15:00:33
【问题描述】:

带有名称和复选框的表单。

我可以把名字放到 MongoDB 里面,但是如何把复选框的值放到 MongoDB 里面呢?

Index.html

<tr>
  <td><input class="form-control" ng-model="film.name"></td> 
  <td><label ng-repeat="role in roles">

   <input type="checkbox" checklist-model="user.roles" checklist-value="role"> {{role}}
 </label></td>

  <td><button class="btn btn-primary" ng-click="addFilm()">Add manga</button></td>
</tr>

收藏电影

db.films.insert({aome:" lara croft", gender:['action', 'adventure'] })

函数添加电影

$scope.addManga = function() {
       $http.post('/films', $scope.film).success(function(response) {
         })};


$scope.roles = [
    'adventure',
    'action'
  ];

  $scope.user = {
    roles: ['user']
  };

我不知道创建一个函数来接收复选框的值并与名称一起插入。

【问题讨论】:

  • 你的后端代码在哪里?你在用 Node 吗?

标签: javascript jquery angularjs mongodb checkbox


【解决方案1】:

查看 https://docs.angularjs.org/api/ng/input/input[checkbox] 的输入[复选框] 的 Angular 文档,并特别注意 ng-model 的内容。

【讨论】:

  • 谢谢,如何添加名称和复选框?
  • 如果您使用 ng-model,数据已经绑定到 $scope,您只需像抓取其他数据一样抓取复选框。你的后端是什么?您如何将数据从 Angular 获取到服务器?
  • Node.js 后端与 Express 和 MongoDB,Serverj.js 选择数据到服务器 db.films.find(function (err, docs) { res.json( docs); 和 controller.js $http.get('/films').success(function(response) { $scope.mangas = response;
  • 听起来很棒。您是否在为数据的客户端填充或服务器端将其保存到 mongo 而苦苦挣扎?
  • 是的。问题是,我不知道函数插入数组的复选框值的方法,因为数组?我想创建一个按流派搜索的函数,所以很容易在“冒险”之后只搜索“动作”,复选框已经填满,只需将mongodb插入为数组
猜你喜欢
  • 1970-01-01
  • 2013-08-16
  • 2013-12-15
  • 1970-01-01
  • 2018-03-14
  • 1970-01-01
  • 2012-12-22
  • 2015-06-23
  • 1970-01-01
相关资源
最近更新 更多