【问题标题】:Using angular to turn a multi-dimensional array into a multi list使用角度将多维数组变成多列表
【发布时间】:2013-02-04 07:57:45
【问题描述】:

js`,我想将一个数组重复到一个列表中

来自: 这是在服务中:

var Response= [
        ["Article One"],
        ["Article Two"],
        ["Article Three"],
        ["Article Images", ["Images 1", "Images 2", "Images 3"] ],
        ["Article Five"]
    ];

并从控制器调用对象:

$scope.Response = function () {
        return ArtikelSucheService.Response;
    };

我想这样重复:

<ul ng-repeat="Article in Response()">
        <li>Article One</li>
        <li>Article Two</li>
        <li>Article Three</li>
        <li>Images 
            <ul ng-repeat="What must stay here?">
                <li>Images 1</li>
                <li>Images 2</li>
                <li>Images 3</li>
            </ul>
        </li>
        <li>Article Five</li>
   </ul>

我不知道,如何在一个数组中重复一个数组。 响应是一个数组。在响应中有 x 个图像。 1 篇文章可以包含多张图片。

谁能帮帮我?

【问题讨论】:

    标签: javascript arrays object angularjs ng-repeat


    【解决方案1】:

    可能像下面这样?

    <ul>
      <li ng-repeat="Article in Response()">
        {{ Article[0] }}
        <ul ng-show="Article[1]">
          <li ng-repeat="img in Article[1]">{{ img }}</li>
        </ul>
      </li>
    </ul>
    

    【讨论】:

      【解决方案2】:
      var Response1= [
              ["Article One"],
              ["Article Two"],
              ["Article Three"],
              ["Article Images", ["Images 1", "Images 2", "Images 3"] ],
              ["Article Five"]
      ];
      

      在html中使用下面的模板

      <ul>
        <li ng-repeat='option in responses1'>
            {{option[0]}}
            <ul>
            <li ng-repeat='suboption in option[1]'>{{suboption}}</li>
          </ul>
            </li>
          </ul>
      

      工作小提琴 http://jsfiddle.net/jw5Qf/1/

      【讨论】:

      • 不需要添加空数组。至少从 1.0.4 开始,如果源数组未定义,则 ng-repeat 将不会执行
      猜你喜欢
      • 2014-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-17
      • 2018-06-12
      • 1970-01-01
      • 2016-01-14
      • 1970-01-01
      相关资源
      最近更新 更多