从数组填充<dl>列表

时间:2016-06-10 03:43:38

标签: javascript html arrays angularjs

我正在使用angularJS并拥有一个javascript对象数组,每个对象都有

Count
ID
Subject

我想使用这个数组来填充这些值:

                            <dl>
                                <dt>Count</dt>
                                <dd>Subject</dd>
                                  <!--all objects should appear as above-->  
                            </dl>

有办法做到这一点吗?

2 个答案:

答案 0 :(得分:1)

$scope.yourArray = [
    {"Count": "something1", "ID":  "something2", "Subject":  "something3"},
    {"Count": "something1", "ID":  "something2", "Subject":  "something3"},
    {"Count": "something1", "ID":  "something2", "Subject":  "something3"},
    {"Count": "something1", "ID":  "something2", "Subject":  "something3"}
]; // On the controller

<dl ng-repeat="item in yourArray">
    <dt>{{item.Count}}</dt>
    <dd>{{item.Subject}}</dd>
</dl>

答案 1 :(得分:1)

试试这个:

<dl ng-repeat="myDataItem in myDataArr">
  <dt>{{ myDataItem.Count }}</dt>
  <dd>{{ myDataItem.Subject }}</dd>
</dl>