如何在简单对象上使用Angular.js ng-repeat

时间:2013-02-21 16:14:30

标签: angularjs

这有什么问题?它输出的列表看起来很奇怪,最后一个元素(正确的)与其余元素不对齐。另外我需要运行一个随机化元素的函数,应该去哪里?

<div ng-controller="getAnswers" id="pannel">
    <div id="base"></div>
    <ul class="answers">
        <li ng-repeat="wrong in answers.incorrect" class="answer" id="wrong{{$index}}">{{wrong}}</li>
        <li class="answer ng-scope" id="correct">{{answers.correct}}</li>
    </ul>
</div>

$ scope.answers看起来像这样

{correct: "작아",
incorrect: ["자가", "작ㅏ", "작"]}

1 个答案:

答案 0 :(得分:0)

我通过将数据更改为此格式并以此方式循环来解决此问题。无论如何,在一次通过中构建UL更有意义。

[
{correct: "correct", text: "작아"}, 
{correct: "incorrect", text: "자가"}, 
{correct: "incorrect", text: "작ㅏ"}, 
{correct: "incorrect", text: "작"}
]