【发布时间】:2017-04-09 19:23:07
【问题描述】:
我在我的应用程序中使用 MEAN 堆栈,AngularJS 作为我的前端。我如何在输入字段中使用 typeahead 来获取 angularjs 中的值,实际上,如果我们使用 select 选项,我们会得到值,但我们期望 type-ahead 选项...请查看 plunker 以获取参考 My Plunker。
在 plunker 中首先选择用于获取无数组值的选项。
第二个选择选项用于获取
user数组中的值。所以我们使用ng-options="item.user.displayName for item in questions"但我们希望使用 typeahead 选项来获取
user数组中的displayNmae值。所以我们像typeahead="item as item.user.displayName for item in questions | filter:$viewValue | limitTo:8"一样使用但我们无法得到答案......如果我们键入下拉菜单需要显示的名称,我们在第三个输入字段中的确切内容...
如果有人知道解决方案,请同时更新 plunker 以了解解决方案。
我的数据:-
$scope.questions = [
{
"_id": "583433ddc021a5d02949a51b",
"user": {
"_id": "5834336ac021a5d02949a51a",
"displayName": "mani R",
"location": "ICF",
"dob": "1991-10-05T18:30:00.000Z",
"religion": "Christian",
"roles": [
"user"
],
"profileImageURL": "modules/users/client/img/profile/default.png"
},
"__v": 0,
"upvoters": [],
"category": "Moral Ethics",
"content": "Dhoni",
"title": "which batsman is best in the world?",
"created": "2016-11-22T12:02:37.376Z"
},
{
"_id": "582c34b3ff26bd603e1e5383",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"dob": "1991-10-04T18:30:00.000Z",
"location": "Icf",
"religion": "Hindu",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/profile/uploads/c756711556ab6864f408697c7a98aedc"
},
"__v": 1,
"upvoters": [],
"users": [],
"comments": [
{
"created": 1479365394684,
"email": "ms@e21designs.com",
"name": "Table 1",
"commentText": "Dhoni"
}
],
"friend_tag": [],
"emotion": "Confused",
"category": "Environment & Health",
"content": "sachin?",
"title": "who is best player in this world?",
"created": "2016-11-16T10:28:03.859Z"
},
{
"_id": "582c3418ff26bd603e1e5382",
"user": {
"_id": "582c1f4b53cf7fec2ddf282e",
"displayName": "selvam R",
"dob": "1991-10-04T18:30:00.000Z",
"roles": [
"kp"
],
"profileImageURL": "modules/users/client/img/profile/default.png"
},
"__v": 0,
"upvoters": [],
"category": "Environment & Health",
"content": "he is tennis player",
"created": "2016-11-16T10:25:28.835Z"
},
{
"_id": "582ad554714543e037cf3bf2",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"dob": "1991-10-04T18:30:00.000Z",
"location": "Icf",
"religion": "Hindu",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/profile/uploads/c756711556ab6864f408697c7a98aedc"
},
"__v": 1,
"upvoters": [
"ms@e21designs.com"
],
"upvotes": 1,
"category": "Moral Ethics",
"created": "2016-11-15T09:28:52.403Z"
},
{
"_id": "5821e7c667b70aac2b8fdfdc",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"dob": "1991-10-04T18:30:00.000Z",
"location": "Icf",
"religion": "Hindu",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/profile/uploads/c756711556ab6864f408697c7a98aedc"
},
"__v": 1,
"upvoters": [
"ms@e21designs.com"
],
"upvotes": 1,
"category": "Religion & Culture",
"created": "2016-11-08T14:57:10.354Z"
}
]
我的 HTML:-
<div style="margin-top: 20px;">
<label style="color: green;">3. Typeahead Not Working</label>
<input ng-model="friend" typeahead-min-length="3" typeahead="item as item.user.displayName for item in questions | filter:$viewValue | limitTo:8">
</div>
- 我们在 Mr.J-Mean 的帮助下得到了答案,但是我们还有一个问题,如果我们在 Typeahead 输入中输入类似
table 1的名称,它会显示为三个Table 1名称,如果我们有相同的名称名称在我们的数据中意味着我们希望只显示一个名称,例如Table 1请帮助我们...请在 plunker 中更新您的答案以及了解解决方案...谢谢
【问题讨论】:
-
你用的是什么预输入插件?
-
感谢您的评论,我们在这里没有使用 typeahead 插件,请查看我的 plunker 以供参考...谢谢....
-
那么预输入是如何工作的呢?
-
如果你知道解决方案请给一些建议和如何使用...谢谢..