如何使用 meanjs 在另一个输入字段中绑定下拉字段值?
How to bind drop down field value in another input field using meanjs?
如何使用 meanjs 在另一个输入字段中绑定下拉字段值。
大家好请看我创建的这个Plunker,
我看的是plunker里面先是我们selectschool
然后是selectschool section
,然后是[=15] =] 可用所以我需要的是 section
需要 bind
在那 input text field
...
例如 :- 如果我们 select 7A (or) 8A
在 section dropdown
中,这个 section value
需要bind
到 input field
,现在它显示错误,如“[object Object]”...那么如何做到这一点。
我的Html:-
<div>
<label>1. Without array value</label>
<select ng-model="question" 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.commentText for item in question.comments">
</select>
{{class.commentText}}
</div>
<div>
<input type="text" ng-model="newclass" ng-bind="newclass=class"/>
</div>
输入字段:-
<div>
<input type="text" ng-model="newclass" ng-bind="newclass=class"/>
</div>
我的数据 :-
$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"
}
],
"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"
}
]
首先有两种方法
简单地将输入 ng-model
设置为 class.commentText
类似
<input type="text" ng-model="class.commentText" />
但是如果您更改输入
,这将导致 select 选项发生变化
第二种方式
在 select 值更改时将值分配给 newClass
<select style="margin-left: 20px;" ng-model="class" ng-change="newClass=class.commentText" ng-options="item.commentText for item in question.comments">
</select>
<input type="text" ng-model="newClass" />
如何使用 meanjs 在另一个输入字段中绑定下拉字段值。
大家好请看我创建的这个Plunker,
我看的是plunker里面先是我们select
school
然后是selectschool section
,然后是[=15] =] 可用所以我需要的是section
需要bind
在那input text field
...例如 :- 如果我们 select
7A (or) 8A
在section dropdown
中,这个section value
需要bind
到input field
,现在它显示错误,如“[object Object]”...那么如何做到这一点。
我的Html:-
<div>
<label>1. Without array value</label>
<select ng-model="question" 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.commentText for item in question.comments">
</select>
{{class.commentText}}
</div>
<div>
<input type="text" ng-model="newclass" ng-bind="newclass=class"/>
</div>
输入字段:-
<div>
<input type="text" ng-model="newclass" ng-bind="newclass=class"/>
</div>
我的数据 :-
$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"
}
],
"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"
}
]
首先有两种方法
简单地将输入 ng-model
设置为 class.commentText
类似
<input type="text" ng-model="class.commentText" />
但是如果您更改输入
,这将导致 select 选项发生变化第二种方式
在 select 值更改时将值分配给 newClass
<select style="margin-left: 20px;" ng-model="class" ng-change="newClass=class.commentText" ng-options="item.commentText for item in question.comments">
</select>
<input type="text" ng-model="newClass" />