在ng-repeat-start和ng-repeat-end中使用范围

时间:2015-08-02 00:12:08

标签: javascript angularjs

我正在尝试将一个字符串放在ng重复的名称下面,但是当我将它放入时,它就不会出现,就像它只是来自{{}}的正常范围一样。

当我把它放在带有列表的ng-repeat中时,它会将整个事物打印得非常广泛,比如将每个字母分成列表的每个部分,这显然不会这样做。

我只需要打印出来自对象名称下方的重要性级别。

$scope.profileCompare = {

        You: {
            questionAnswer: [false, true, false, false, false, false],
            percent: ['20%', '40%', '60%', '80%', '100%'],
            questionImportance: "Unimportant"
        },
        Pizza: {
            questionAnswer: [true, false, false, false, false, false],
            percent: ['20%', '40%', '60%', '80%', '100%'],
            questionImportance: "Very important"
        },
        Greenie: {
            questionAnswer: [false, true, false, false, true, false],
            percent: ['20%', '40%', '60%', '80%', '100%'],
            questionImportance: "Important"
        }
    }
 <div ng-repeat-start="(key, value) in profileCompare" style="float: left">{{key}} <br> 
  <ul class="comparison-list">
    <li ng-repeat="importance in value.questionImportance track by $index">
      {{importance}}
    </li>
  </ul>
  </div>
  <ul ng-repeat-end class="comparison-list" style="float: right">
    <li ng-repeat="answer in value.questionAnswer track by $index" style="position:relative; " class="fa-li fa" ng-class="{green:answer, red:!answer, 'fa-check-square':answer, 'fa-square':!answer}">
    </li>
    <br>
    <li ng-repeat="percent in value.percent track by $index" style="position:relative; float:right">
      {{percent}}
  </li>

1 个答案:

答案 0 :(得分:0)

我不是百分之百确定我理解你想要什么,但我会做出一些假设。

我稍微更改了你的对象,以便它被包裹在一个数组中并且还推送了&#34; name&#34;进入自己的财产。

$scope.profileCompare = [{
    name: 'You',
    stats: {
        questionAnswer: [false, true, false, false, false, false],
        percent: ['20%', '40%', '60%', '80%', '100%'],
        questionImportance: "Unimportant"
    }
}, {
    name: 'Pizza',
    stats: {
        questionAnswer: [true, false, false, false, false, false],
        percent: ['20%', '40%', '60%', '80%', '100%'],
        questionImportance: "Very important"
    }
}, {
    name: 'Greenie',
    stats: {
        questionAnswer: [false, true, false, false, true, false],
        percent: ['20%', '40%', '60%', '80%', '100%'],
        questionImportance: "Important"
    }
}];

以下是您可以在几个无序列表中表示这一点的方法。再一次,我不明白你想要实现的目标,但我希望这能让你到达你需要去的地方:

<div ng-repeat-start="profile in profileCompare" class="header">{{profile.name}}   
</div>
<div>
    {{profile.stats.questionImportance}} 
</div>
<ul ng-repeat="qanswer in profile.stats.questionAnswer track by $index">
    <li>{{qanswer}}</li>
</ul>  
<ul ng-repeat="pct in profile.stats.percent track by $index">
    <li>{{pct}}</li>
</ul>   
<div ng-repeat-end>
    <br />
</div>

<强> jfiddle here