来自另一个json的角度ng-repeat查找

时间:2015-08-20 10:43:20

标签: json angularjs

在下面的例子中,我从一个JSON& amp;循环遍历mgId。使用ng-repeat打印mg名称。我有另一个JSON,它有关联用户的mg。如何在ng-repeat内打印相应mgId的指定用户名?这是http://fiddle.jshell.net/7Ly6q14c/9/ 基本上我正在循环使用一个JSON&我想从当前循环中的另一个基于JSON的变量加载一些值。我不想对控制器进行更改。

2 个答案:

答案 0 :(得分:1)

    <div ng-repeat="x in names">
      <div>{{x.name}}
        <span ng-repeat="y in usernames track by $index">
          <input ng-model="y.assignedUserNames" ng-if="y.mgId==x.mgId "></input>
        </span>
      </div>
    </div>

工作plunker

答案 1 :(得分:0)

你可以在代码中做这样的事情。

&#13;
&#13;
var app = angular.module('app', []);
app.controller('ctrl',
  function ($scope) {
        $scope.masterClausesList = 
    [  
{
    "Id":1,
    "ID":1,
    "Title":"Platform",
    "Desc":"Our Platform provides our users with a variety of resources to facilitate organizing of groups, (a \"Meetup\" or \"Meetup Group\"), and creating of a network (\"Meetup Everywhere\").",
    "Checked":null,
    "CCategory":"Company Contracts"
  },
  {
    "Id":2,
    "ID":2,
    "Title":"Membership",
    "Desc":"Our Platform provides our users with a variety of resources to facilitate organizing of groups, (a \"Meetup\" or \"Meetup Group\"), and creating of a network (\"Meetup Everywhere\").",
    "Checked":null,
    "CCategory":"Company Contracts"
  },
  {
    "Id":3,
    "ID":3,
    "Title":"Payment",
    "Desc":"Limited to 100 days",
    "Checked":null,
    "CCategory":"Company Contracts"
  }
];
    $scope.selectedContract = [];
    $scope.selectedContract.clausesSelected = 
    [
     {
        "Id":1,
        "ID":1,
        "Title":"Platform",
        "SortId":null,
        "Desc":"Our Platform provides our users with a variety of resources to facilitate organizing of groups, (a \"Meetup\" or \"Meetup Group\"), and creating of a network (\"Meetup Everywhere\").",
        "CCategory":null,
        "CUSER":null,
        "CCONTRACTHDRID":"6",
        "CCLAUSEMSTID":"1"
      }
    ];

    $scope.kk = '___';



var k2 = [];
angular.forEach($scope.masterClausesList, function (value1,key1) {
  angular.forEach($scope.selectedContract.clausesSelected, function (value2,key2) {
    
  });
});

var log = [];
angular.forEach($scope.masterClausesList, function(value) {
  angular.forEach($scope.selectedContract.clausesSelected, function (value2) {
    if(value2.CCLAUSEMSTID == value.Id){
      value.Checked = true
      this.push(value);
    }else{
     //this.push(value);
    }
  },log);
}, log);

$scope.kk = log;
});
&#13;
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
  <body ng-app="app" ng-controller="ctrl">
    {{kk}}
  </body>
&#13;
&#13;
&#13;