2017-07-03 11 views
0

をangularjs最初に私のキーが表示されますようですその後、私のデータの問題は、私のデータであります逆オブジェクト現在、私は、私はデータでいくつかの質問とキー 私はデータを表示したいを持っている問題で立ち往生しています

{ 
    "0": [ 
    { 
     "question": "How often is real property re-assessed (or revalued)?", 
     "id": 1, 
     "section": "Assessment", 
     "sectionId": 2, 
     "check": true, 
     "index": 0 
    }, 
    { 
     "question": "How often second?", 
     "id": 3, 
     "section": "Assessment", 
     "sectionId": 2, 
     "check": true, 
     "index": 0 
    }, 
    { 
     "question": "How often third?", 
     "id": 2, 
     "section": "Assessment", 
     "sectionId": 2, 
     "check": true, 
     "index": 0 
    }, 
    { 
     "key": "Survey Meta Data" 
    } 
    ], 
    "1": [ 
    { 
     "question": "When are New Assessment Notices sent out?", 
     "id": 3, 
     "section": "Assessment", 
     "sectionId": 2, 
     "check": true, 
     "index": 1 
    }, 
    { 
     "key": "Assessment" 
    } 
    ] 
} 

私はこのようなものだ、このデータをNG・リピートを使用する場合:私の質問は最初に表示された後、キーが表示されますが、

<div ng-repeat="data in viewQuestions"> 
<div class="panel panel-default" ng-repeat="value in data"> 
    {{value.key}} 

    label>{{value.question}} </label> 

    </div> 
     </div> 

を、私は、キーを最初に表示したいとth質問 途中、私は、彼らが挿入され、最初のデータ・キーであるため、問題は、質問が最初に表示されている知っています。

私はそうキーが必要なものまず、私の質問

答えて

0

を表示されているデータを逆にすることができます任意の方法がありますが、あなたが必要とする形式にデータ構造を変更するには、データのマッサージです。 が最初にこのフィルタを使用してアレイを反転:

var processedData = []; 
angular.forEach(data, function(item) { 
    var section = { questions: [] }; 

    angular.forEach(data, function(question) { 
    if (question.key) { // this is key, not question 
     section.key = question.key; 
    } 
    else { 
     section.questions.push(question); 
    } 
    }); 

    processedData.push(section); 
}); 
+0

質問.KEYは、そのデータは何もありません最初に、キーが表示されますあなたは、あなたのデータに配列の配列を持っている@KumailHussain .question –

+0

は、あなたがそれらを結合する必要があるかもしれませんか?あなたが結合することにより、何を意味するか – Icycool

+0

? –

0

掘り後、私は完全に正常に動作解決策を考え出した

.filter("reverse", function(){ 
    return function(items){ 
     return items.slice().reverse(); // Create a copy of the array and reverse the order of the items 
    }; 
}); 

とhtmlで

はちょうどこの行を追加します

<div class="panel panel-default" ng-repeat="value in data |reverse"> 

は今の質問

関連する問題