使用 meanjs 从对象值数组中获取下拉列表?
Get drop down from array of object values using meanjs?
我正在尝试获取 comments
数组中的下拉列表或 select 字段的值。
我在 drop down
中尝试 comments
对象数组 commentText
值,如何在 ng-option
中执行此操作? My Plunker
例如:
我首先做了下拉 ng-option
,没有像 ng-options="item.title for item in questions"
这样的数组值。
我正在寻找下拉列表中的对象值 [commentText": "7A"]
的注释数组我该怎么做。
我试过了 ng-options="item for item.comments.commentText in questions"
它对我不起作用。如何解决?
我的数据:
$scope.questions = [
{
"_id": "59df6c37b6748bc809050699",
"user": {
"_id": "59df6a76b6748bc809050697",
"profileImageURL": "modules/users/client/img/profile/default.png"
},
"__v": 1,
"comments": [
{
"created": 1507897712831,
"email": "ms@e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "7A"
}
],
"questionid": "",
"created": "2017-10-12T13:20:55.383Z"
}
]
我的Html:
<label>1. Without array value</label>
<select ng-model="class" ng-options="item.title for item in questions">
</select>
</div>
<div style="margin-top: 11px;">
<label>2. With comments array value</label>
<select style="margin-left: 20px;" ng-model="class" ng-options="item for item.comments.commentText in questions">
</select>
</div>
寻找第二个解决方案是:-
- 我只是想如果我们 select 问题,评论 select 只过滤这个问题的评论...怎么做...谢谢
只需将您的第二个 select 更改为:-
<select style="margin-left: 20px;" ng-model="class" ng-options="item.commentText for item in question.comments">
</select>
var myApp = angular.module('exApp',[]);
myApp.controller('myctrl', function($scope){
$scope.questions = [
{
"_id": "59df6c37b6748bc809050699",
"user": {
"_id": "59df6a76b6748bc809050697",
"profileImageURL": "modules/users/client/img/profile/default.png"
},
"__v": 1,
"openeyers": [],
"openeyes": 0,
"upvoters": [],
"upvotes": 0,
"isLiked": false,
"users": [],
"comments": [
{
"created": 1507897712831,
"email": "ms@e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "7A"
},
{
"created": 1507897712831,
"email": "ms@e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "9A"
},
{
"created": 1507897712831,
"email": "ms@e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "10A"
}
],
"questionid": "",
"title": "Silver jublie",
"created": "2017-10-12T13:20:55.383Z"
},
{
"_id": "59df6c37b6748bc809050699",
"user": {
"_id": "59df6a76b6748bc809050697",
"displayName": "Maniselvam selvam",
"dob": "1991-05-10T07:00:00.000Z",
"profileImageURL": "modules/users/client/img/profile/default.png"
},
"__v": 1,
"openeyers": [],
"users": [],
"comments": [
{
"created": 1507897712831,
"email": "ms@e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "8A"
}
],
"questionid": "",
"title": "Public School",
"created": "2017-10-12T13:20:55.383Z"
}
];
$scope.editClass = function(section){
$scope.sectionwithObject = section;
$scope.sectionOnly=section.commentText;
$scope.newLink = section.link;
}
});
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular.min.js"></script>
</head>
<body ng-app="exApp" ng-controller="myctrl">
<div>
<div>
<label>1. Without array value</label>
<select ng-model="ques" ng-options="item.title for item in questions">
</select>
</div>
<div style="margin-top: 11px;">
<label>2. With comments array value</label>
<select style="margin-left: 20px;" ng-model="commen" ng-options="item as item.commentText for item in ::ques.comments" ng-change="editClass(commen)">
</select>{{commen}}
<br><br>
<div>
<input type="text" ng-model="sectionwithObject.commentText"/><br><br>
<input type="text" ng-model="sectionOnly"/>
</div><br>
<div>
<lable> Link</lable>
<input type="text" ng-model="sectionwithObject.link" /><br><br>
<input type="text" ng-model="newLink" />
</div>
</div>
</div>
</body>
</html>
我正在尝试获取
comments
数组中的下拉列表或 select 字段的值。我在
drop down
中尝试comments
对象数组commentText
值,如何在ng-option
中执行此操作? My Plunker
例如:
我首先做了下拉
ng-option
,没有像ng-options="item.title for item in questions"
这样的数组值。我正在寻找下拉列表中的对象值
[commentText": "7A"]
的注释数组我该怎么做。我试过了
ng-options="item for item.comments.commentText in questions"
它对我不起作用。如何解决?
我的数据:
$scope.questions = [
{
"_id": "59df6c37b6748bc809050699",
"user": {
"_id": "59df6a76b6748bc809050697",
"profileImageURL": "modules/users/client/img/profile/default.png"
},
"__v": 1,
"comments": [
{
"created": 1507897712831,
"email": "ms@e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "7A"
}
],
"questionid": "",
"created": "2017-10-12T13:20:55.383Z"
}
]
我的Html:
<label>1. Without array value</label>
<select ng-model="class" ng-options="item.title for item in questions">
</select>
</div>
<div style="margin-top: 11px;">
<label>2. With comments array value</label>
<select style="margin-left: 20px;" ng-model="class" ng-options="item for item.comments.commentText in questions">
</select>
</div>
寻找第二个解决方案是:-
- 我只是想如果我们 select 问题,评论 select 只过滤这个问题的评论...怎么做...谢谢
只需将您的第二个 select 更改为:-
<select style="margin-left: 20px;" ng-model="class" ng-options="item.commentText for item in question.comments">
</select>
var myApp = angular.module('exApp',[]);
myApp.controller('myctrl', function($scope){
$scope.questions = [
{
"_id": "59df6c37b6748bc809050699",
"user": {
"_id": "59df6a76b6748bc809050697",
"profileImageURL": "modules/users/client/img/profile/default.png"
},
"__v": 1,
"openeyers": [],
"openeyes": 0,
"upvoters": [],
"upvotes": 0,
"isLiked": false,
"users": [],
"comments": [
{
"created": 1507897712831,
"email": "ms@e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "7A"
},
{
"created": 1507897712831,
"email": "ms@e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "9A"
},
{
"created": 1507897712831,
"email": "ms@e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "10A"
}
],
"questionid": "",
"title": "Silver jublie",
"created": "2017-10-12T13:20:55.383Z"
},
{
"_id": "59df6c37b6748bc809050699",
"user": {
"_id": "59df6a76b6748bc809050697",
"displayName": "Maniselvam selvam",
"dob": "1991-05-10T07:00:00.000Z",
"profileImageURL": "modules/users/client/img/profile/default.png"
},
"__v": 1,
"openeyers": [],
"users": [],
"comments": [
{
"created": 1507897712831,
"email": "ms@e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "8A"
}
],
"questionid": "",
"title": "Public School",
"created": "2017-10-12T13:20:55.383Z"
}
];
$scope.editClass = function(section){
$scope.sectionwithObject = section;
$scope.sectionOnly=section.commentText;
$scope.newLink = section.link;
}
});
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular.min.js"></script>
</head>
<body ng-app="exApp" ng-controller="myctrl">
<div>
<div>
<label>1. Without array value</label>
<select ng-model="ques" ng-options="item.title for item in questions">
</select>
</div>
<div style="margin-top: 11px;">
<label>2. With comments array value</label>
<select style="margin-left: 20px;" ng-model="commen" ng-options="item as item.commentText for item in ::ques.comments" ng-change="editClass(commen)">
</select>{{commen}}
<br><br>
<div>
<input type="text" ng-model="sectionwithObject.commentText"/><br><br>
<input type="text" ng-model="sectionOnly"/>
</div><br>
<div>
<lable> Link</lable>
<input type="text" ng-model="sectionwithObject.link" /><br><br>
<input type="text" ng-model="newLink" />
</div>
</div>
</div>
</body>
</html>