如何从另一个数组中选择一个选定的项目? Angularjs

发布于 2025-01-21 22:31:25 字数 1238 浏览 0 评论 0原文

请提供帮助,我不明白,如果选择的项目来自其他地方并且处于不同的数组中,我不明白该项目如何选择它。如果不可能,是否可以在当前数组中搜索一个项目,并将其选择为选择项目,如果是,请给我一个示例。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌味 2025-01-28 22:31:25
$scope.initialMention = $scope.mentions.flat().slice(0,2)
$scope.initialMention = $scope.mentions.flat().slice(0,2)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文