如何从另一个数组中选择一个选定的项目? Angularjs
请提供帮助,我不明白,如果选择的项目来自其他地方并且处于不同的数组中,我不明白该项目如何选择它。如果不可能,是否可以在当前数组中搜索一个项目,并将其选择为选择项目,如果是,请给我一个示例。 PS: 如果我从类似的现有项目中选择原始项目,我就可以设置一个项目,但想从其他数组中选择它
$scope.initialMention = [
$scope.mentions[0][0],
$scope.mentions[1][0]
];
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.mentions = [
[
{
"name": "[email protected]",
"uuid": "31a52cab-429d-4efa-91dc-d79b154dd4f9",
"type": "Users",
"selected": false,
},
{
"name": "[email protected]",
"uuid": "020e5b7c-98b6-457a-a90e-d78253eef11d",
"type": "Users",
"selected": false,
},
{
"name": "testTeam
Please help, I don't understand how I can select a selected item if it comes from somewhere else and is in a different array. If this is not possible, is it possible to search for an item in the current array and select it as a select item if yes, can you give me an example please.
PS:
I was able to set an item if I selected it as the original from an existing item like this, but would like to select it from a different array
$scope.initialMention = [
$scope.mentions[0][0],
$scope.mentions[1][0]
];
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.mentions = [
[
{
"name": "[email protected]",
"uuid": "31a52cab-429d-4efa-91dc-d79b154dd4f9",
"type": "Users",
"selected": false,
},
{
"name": "[email protected]",
"uuid": "020e5b7c-98b6-457a-a90e-d78253eef11d",
"type": "Users",
"selected": false,
},
{
"name": "testTeam ????",
"uuid": "fe5b143c-c6c2-4d34-a152-2a679899541d",
"type": "Teams",
"selected": false,
},
{
"name": "41335412351235 ????",
"uuid": "d751eb81-7363-4f32-a91c-dc6c69d1c113",
"type": "Teams",
"selected": false,
}
],
[
{
"name": "[email protected]",
"uuid": "31a52cab-429d-4efa-91dc-d79b154dd4f9",
"type": "Users",
"selected": false,
},
{
"name": "[email protected]",
"uuid": "020e5b7c-98b6-457a-a90e-d78253eef11d",
"type": "Users",
"selected": false,
},
{
"name": "testTeam ????",
"uuid": "fe5b143c-c6c2-4d34-a152-2a679899541d",
"type": "Teams",
"selected": false,
},
{
"name": "41335412351235 ????",
"uuid": "d751eb81-7363-4f32-a91c-dc6c69d1c113",
"type": "Teams",
"selected": false,
}
]
]
$scope.initialMention = [
{
"name": "testTeam ????",
"uuid": "fe5b143c-c6c2-4d34-a152-2a679899541d",
"type": "Teams",
"selected": false,
},
{
"name": "41335412351235 ????",
"uuid": "d751eb81-7363-4f32-a91c-dc6c69d1c113",
"type": "Teams",
"selected": false,
}
];
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="[email protected]" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js" data-semver="1.0.7"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<br />
<br />
<br />
<div ng-repeat="mention in mentions">
<select
ng-model="initialMention[$index]"
ng-options="item as item.name for item in mention">
</select>
<br />
{{ initialMention[$index]}}
<br />
{{mention[$index]}}
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)