2017-05-25 80 views
0

我在低於該代碼:不容訪問數組項

<div ng-repeat="person in Emotions" class="crop-item"> 
    <div class="text-left"> 
    <ul class="list-group no-buletts"> 

     <li class="list-group-item" style="width: 300px;"> 
     <img class="crop-img" alt="crop image" src="http://192.168.153.131:7000/tmp/{{Emotions['emotion-original-image-ref']}}.jpg.crop-{{$index}}.jpg"></img> 
     Top score: {{Emotions["emotion-top-scores"].$index}} 

     </li> 

     <li ng-repeat='(scoreTitle,scoreValue) in person.scores' class="list-group-item"> 
     <div class="row"> 
      <div class="col-md-6 text-left"> 
      <label for="{{scoreTitle}}">{{scoreTitle}}: </label> 
      </div> 
      <div class="col-md-6 text-left"> 
      {{scoreValue * 100 | number:2}} % 
      </div> 
     </div> 
     </li> 

    </ul> 
    </div> 
</div> 

我有具有此內容這種「情緒」對象:

{ 
    "emotion-status-code": 200, 
    "emotion-response": [{ 
    "faceRectangle": { 
     "height": 72, 
     "left": 147, 
     "top": 122, 
     "width": 72 
    }, 
    "scores": { 
     "anger": 0.00165787316, 
     "contempt": 0.000218306363, 
     "disgust": 0.0000283911031, 
     "fear": 3.707502e-7, 
     "happiness": 1.67207048e-8, 
     "neutral": 0.948927, 
     "sadness": 0.04916397, 
     "surprise": 0.000004111683 
    } 
    }], 
    "emotion-original-image-ref": "e8c3a383-bba8-4015-a9de-a5bbc70843b2", 
    "emotion-top-scores": ["neutral"] 
} 

的問題是在該片段就在這裏:

Top score: {{Emotions["emotion-top-scores"].$index}} 

我檢查了「$指數」和it's使指數從「NG重複」預期,但我不能ACC這是價值,我不知道爲什麼。我相信我在做一些愚蠢的事情。我試圖做到這一點:

Top score: {{Emotions["emotion-top-scores"][$index]}} 

Top score: {{Emotions["emotion-top-scores"][0]}} 

又失敗了。

請你幫我解決這個「史詩般的」情況嗎?

+0

什麼是{{Emotions [「emotion-top-scores」]}}打印 – ukn

+0

什麼都不打印...... –

+0

好吧,試試訪問你的屬性吧:Emotions.emotion-top-scores – ukn

回答

0

嗯,我做到了!但吸引一個醜陋的XHG。我創建了一個'ng-model'變量,並通過控制器直接在這個變量上寫入響應體的內容。工作,但很爛!在控制器...

$scope.topScores = res["emotion-top-scores"]; 

在HTML

<li class="list-group-item" style="width: 300px;" ng-model="topScores" > 

希望有更好的解決方案。真的很糟糕!我真的很慚愧!