用于bootstrap-ui选项卡的AngularJS ng-repeat

皮亚诺克

我正在使用angularjs和bootstrap-ui构建一些选项卡。

我想要两个标签:

成绩和入学考试。我的JSON看起来像这样(如果需要,我可以更改它):

[
      {
        "name":"University of Aberdeen",
        "sections": [
          {
            "title": "Grades",
            "data" : [
              {
                "heading": "GCE - AS Levels",
                "paragraph": "Do not currently form part of academic requirement. AS module resits are permitted providing the final three A levels are undertaken simultaneously over two years of study. GCSE English and Maths needed at grade C minimum."
              },
              {
                "heading": "Re-application",
                "paragraph": "Reapplication is accepted with no disadvantage to the applicant."
              }
            ]
          },
           {
            "title": "Entrance exam",
            "data" : [
              {
                "heading": "GCE - AS Levels",
                "paragraph": "Do not currently form part of academic requirement. AS module resits are permitted providing the final three A levels are undertaken simultaneously over two years of study. GCSE English and Maths needed at grade C minimum."
              },
              {
                "heading": "Re-application",
                "paragraph": "Reapplication is accepted with no disadvantage to the applicant."
              }
            ]
          }
        ]
      }

]

我正在尝试使用ng-repeat,在“成绩”选项卡中,您只能看到第一组数据,在第二个选项卡中,您只能看到第二个数据数组。

<tabset type="pills">
 <tab ng-repeat="tab in tabs" heading="{{tab.title}}" select="getContent()" active="tab.active" disabled="tab.disabled">
      <h1>{{tab.title}}</h1>
        <div ng-repeat="item in tabs.content">
          <div ng-repeat="item in item.sections">
            <div ng-repeat="item in item.data">
              <h3>{{item.heading}}</h3>
              <p>{{item.paragraph}}</p>
            </div>
          </div>
        </div>
      </tab>
    </tabset>

当前,两组数据都被拉入两个选项卡。任何建议将被认真考虑。提前致谢。

帕特里克·莫塔德

好吧,看完您的Plunkr之后,我明白了您的问题。请尝试以下操作:

  <tab ng-repeat="tab in tabs" heading="{{tab.title}}" select="getContent()" active="tab.active" disabled="tab.disabled">
    <div ng-hide="!tabs.isLoaded">
      <h1>{{tab.title}}</h1>
      <div ng-repeat="item in tabs.content">
        <p>{{item.fruit[$parent.$index]}}</p>
      </div>
    </div>
    <div ng-hide="tabs.isLoaded"><h3>Loading...</h3></div>
  </tab>

此解决方案将在显示键值对index = $parent.$index看起来像:{"Apple":"Apple content goes here"}对于Apple标签和{"Pear":"Pear content goes here"}pear标签。为了仅将其范围缩小到该值,您必须说item.fruit[$parent.$index]["Apple"]苹果标签在此处显示苹果内容,并且说item.fruit[$parent.$index]["Pear"]标签对。但是,这对我们没有帮助,因此我建议进行重构。

也许更抽象的东西?也许像...

[
 {
   "fruits":
      [
        {
          "name": "Apple",
          "content" : "content goes here"
        },
        {
          "name": "Pear",
          "content": "pear content goes here"
        }
      ]
 }
]

具有称为“水果”的属性的对象,该属性是水果对象的数组。每个水果对象都有名称和内容作为键。这样,您就可以始终在ng-repeat中使用诸如item.fruit [$ parent。$ index] [“ Name”]之类的东西,并且它将始终输出相应的名称。

如果您有任何问题,请告诉我。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Angularjs 选项卡仅用于使用 ng-repeat 的唯一数组元素

来自分类Dev

带有ng-repeat的有角ui-bootstrap:如果没有选项卡,则不会选择新选项卡

来自分类Dev

AngularJS和UI-Bootstrap选项卡,使用ng-class修改选项卡

来自分类Dev

带有ng-repeat的AngularJS选项卡

来自分类Dev

Angular UI Bootstrap选项卡+ ng-include

来自分类Dev

AngularJS UI Bootstrap选项卡示例

来自分类Dev

使用ng-show时,ui-bootstrap选项卡显示不正确的选项卡内容

来自分类Dev

如何使用ng-show / ng-hide隐藏Angular Bootstrap UI中的选项卡

来自分类Dev

如何使用ng-show / ng-hide隐藏Angular Bootstrap UI中的选项卡

来自分类Dev

AngularJS:ng-repeat用于纯文本

来自分类Dev

AngularJS:ng-repeat用于纯文本

来自分类Dev

AngularJS Bootstrap-ui选项卡引入动态内容

来自分类Dev

AngularJS的Bootstrap选项卡

来自分类Dev

AngularJS单控制器,用于ng-repeat-start和ng-repeat-end

来自分类Dev

用于选择框选项的简单ng-Repeat

来自分类Dev

angularjs-ng-repeat仅适用于$ index

来自分类Dev

引导程序选项卡上的ng-repeat tab-content / tab-pane

来自分类Dev

在uib-tab中添加具有active和ng-repeat的选项卡

来自分类Dev

ng-repeat中的UI Bootstrap单选按钮

来自分类Dev

带有ng-repeat的ui.bootstrap.buttons

来自分类Dev

带有ng-repeat的ui.bootstrap.buttons

来自分类Dev

ng-repeat中的UI Bootstrap单选按钮

来自分类Dev

Bootstrap Popover在AngularJs ng-repeat内部不起作用

来自分类Dev

AngularJS和Bootstrap:ng-repeat导致列表丢失格式

来自分类Dev

AngularJS与Bootstrap选项卡冲突

来自分类Dev

带有UI-Bootstrap选项卡和UI-Router的Angularjs导航菜单

来自分类Dev

带有UI-Bootstrap选项卡和UI-Router的Angularjs导航菜单

来自分类Dev

AngularJS ng内单击ng-repeat

来自分类Dev

ng-if在ng-repeat angularjs中

Related 相关文章

  1. 1

    Angularjs 选项卡仅用于使用 ng-repeat 的唯一数组元素

  2. 2

    带有ng-repeat的有角ui-bootstrap:如果没有选项卡,则不会选择新选项卡

  3. 3

    AngularJS和UI-Bootstrap选项卡,使用ng-class修改选项卡

  4. 4

    带有ng-repeat的AngularJS选项卡

  5. 5

    Angular UI Bootstrap选项卡+ ng-include

  6. 6

    AngularJS UI Bootstrap选项卡示例

  7. 7

    使用ng-show时,ui-bootstrap选项卡显示不正确的选项卡内容

  8. 8

    如何使用ng-show / ng-hide隐藏Angular Bootstrap UI中的选项卡

  9. 9

    如何使用ng-show / ng-hide隐藏Angular Bootstrap UI中的选项卡

  10. 10

    AngularJS:ng-repeat用于纯文本

  11. 11

    AngularJS:ng-repeat用于纯文本

  12. 12

    AngularJS Bootstrap-ui选项卡引入动态内容

  13. 13

    AngularJS的Bootstrap选项卡

  14. 14

    AngularJS单控制器,用于ng-repeat-start和ng-repeat-end

  15. 15

    用于选择框选项的简单ng-Repeat

  16. 16

    angularjs-ng-repeat仅适用于$ index

  17. 17

    引导程序选项卡上的ng-repeat tab-content / tab-pane

  18. 18

    在uib-tab中添加具有active和ng-repeat的选项卡

  19. 19

    ng-repeat中的UI Bootstrap单选按钮

  20. 20

    带有ng-repeat的ui.bootstrap.buttons

  21. 21

    带有ng-repeat的ui.bootstrap.buttons

  22. 22

    ng-repeat中的UI Bootstrap单选按钮

  23. 23

    Bootstrap Popover在AngularJs ng-repeat内部不起作用

  24. 24

    AngularJS和Bootstrap:ng-repeat导致列表丢失格式

  25. 25

    AngularJS与Bootstrap选项卡冲突

  26. 26

    带有UI-Bootstrap选项卡和UI-Router的Angularjs导航菜单

  27. 27

    带有UI-Bootstrap选项卡和UI-Router的Angularjs导航菜单

  28. 28

    AngularJS ng内单击ng-repeat

  29. 29

    ng-if在ng-repeat angularjs中

热门标签

归档