angularjs 数组合并的问题

小轩1986 发布于 2016/06/28 14:19
阅读 2K+
收藏 0

为什么quest.answer就是出不来,我只想把数组array中的answer放入数组questions中,两个数组相关联的array数组的cid 和question的id值是相等的

html

<tr ng-repeat="quest in questions>

            <td ng-bind="quest.q_number"></td>
            <td ng-bind="quest.answer"></td>

</tr>

js

 $scope.questions = [];         
 $scope.last_questions = [];    
 $http.get('{{ action('xxxx@getAjaxQuestions') }}').then(function(response) {
        $scope.questions = response.data.questions;
        $scope.array = response.data.array;
  
         for(var i = 0; i<$scope.last_questions.length; i++){
           var temp = {};
           $scope.temp.id =  $scope.array[i].cid;
           $scope.temp.q_number = $scope.array[i].answer;
              questions.push(temp);
         }


      }, function(response) {


      });

加载中
1
wayne_cute
wayne_cute
$scope.nowtimes = function(){
$scope.questions = [{id:1,q_number:1},{id:2,q_number:2},{id:3,q_number:3},{id:4,q_number:4}];
$scope.array = [{cid:1,answer:1111},{cid:2,answer:2222},{cid:3,answer:3333},{cid:4,answer:4444}];
$scope.questionsList=[];
for(var i=0;i<$scope.array.length;i++){
for(var j=0;j<$scope.questions.length;j++){
if($scope.array[i].cid==$scope.questions[j].id){
$scope.temp = {};
$scope.temp.id=$scope.questions[i].id;
$scope.temp.q_number=$scope.questions[i].q_number;
$scope.temp.answer=$scope.array[j].answer;
$scope.questionsList.push($scope.temp);
}
}
}
}
$scope.nowtimes();
0
安宇雨
安宇雨
强大的$filter
小轩1986
小轩1986
能在具体点吗
0
wayne_cute
wayne_cute
一个循环是不行的,还有
返回顶部
顶部