search

Home  >  Q&A  >  body text

angular.js - json对象可以使用ng-repeat吗

一个jsonobject, 希望可以遍历获取key和value, 是否可以用ng-repeat的方式获取,或者别的简单的方式,达到类似以下的效果;
以下jsonobject使用ng-repeat会报错

 
$scope.data =  {'aaa' : '123' , ‘bbb’:'456','ccc':'789'}

<p ng-repeat="m in data">
  key = {{m.key}}
  value = {{m.value}}
</p>
过去多啦不再A梦过去多啦不再A梦2745 days ago545

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-15 17:07:43

    <p ng-repeat="(key, val) in data">
      key = {{key}}
      value = {{val}}
    </p>

    reply
    0
  • 高洛峰

    高洛峰2017-05-15 17:07:43

    You can refer to angular’s ​​official explanation of ngRepeat:

    Iterating over object properties
    It is possible to get ngRepeat to iterate over the properties of an object using the following syntax:

    <p ng-repeat="(key, value) in myObj"> ... </p>

    reply
    0
  • Cancelreply