简体   繁体   English

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

[英]ng-repeat on bootstrap tab-content/tab-pane

I am having trouble getting my tab content to appear properly on page load. 我无法让我的标签页内容在页面加载时正确显示。 What I have is a factory of Objects called apiList , I then use two ng-repeats , one which hits each object in the apiList, then the next one which iterates through that object and puts all of its data on the page. 我拥有的是一个名为apiList的对象工厂,然后使用两个ng-repeats ,其中一个命中apiList中的每个对象,然后下一个迭代该对象并将其所有数据放在页面上。 I use #tab{{$index}} to keep my data-toggles aligned between the buttons and tab-panes. 我使用#tab{{$index}}来保持我的数据切换在按钮和标签窗格之间对齐。

The problem seems to be with how I use the active attribute on my tab-pane . 问题似乎出在我如何在tab-pane上使用active属性。

I have three known test cases so far. 到目前为止,我有三个已知的测试用例。

  1. I can only get information from the first Object by using the condition ng-class="{ 'active': $index == 0}" as in.. <div ng-repeat="(key, data) in apiList[0]" class="tab-pane active" id="tab{{$index}}" ng-class="{ 'active': $index == 0}"> 我只能通过使用条件ng-class="{ 'active': $index == 0}"从第一个对象获取信息<div ng-repeat="(key, data) in apiList[0]" class="tab-pane active" id="tab{{$index}}" ng-class="{ 'active': $index == 0}"> 在此处输入图片说明

  2. If I remove the conditional from the line then nothing appears 如果我从行中删除条件,则什么也不会出现 在此处输入图片说明

  3. And if I just add active to the pane value (with no condition) (ie <div ng-repeat="(key, data) in apiList[0]" class="tab-pane active" id="tab{{$index}}"> They all appear. 而且,如果我只是将active添加到窗格值(无条件)(即<div ng-repeat="(key, data) in apiList[0]" class="tab-pane active" id="tab{{$index}}">它们全部出现。 在此处输入图片说明

So my problem seems to be with how I need to turn on/off my active for the ng-repeat and I am just getting lost. 因此,我的问题似乎在于我需要如何为ng-repeat开启/关闭活动状态,而我正迷路。

Also, clicking on accounts/customers does not update the tabs. 另外,单击帐户/客户不会更新选项卡。 They both have the right data-toggle ID's (0 and 1) in respect to the tab-panes so I assume it is part of the active issue. 他们都有在对于制表窗格右侧数据切换的ID(1 0),所以我认为它是部分active的问题。 And whenever I click on my tab panes, they do expand just fine. 而且,每当我单击选项卡窗格时,它们的扩展范围都很好。

Here is my Factory, ng-repeat(s), and the code that was my original setup (functional). 这是我的工厂,ng-repeat和代码,这是我最初的设置(功能性)。

Factory

.factory('APIMethodService', [function() {
  var Head = "api.verifyvalid";
  return {
    apis: [
      {
      accounts: [
        {
          parameters : [
            {
              name : "Accounts",
              version : "1.0"
            }
          ],
          uri: Head + "/v1/accounts/account_number",
          methods : [
            {
              name: "Account Number",
              desc: "Returns the account number."
            }, {
              name: "Account Money",
              desc: "Returns the monetary amount within the account."
            }
          ]
        },
        {
          parameters : [
            {
              name : "Accounts",
              version : "2.0"
            }
          ],
          uri: Head + "/v2/accounts/account_number",
          methods: [
            {
              name: "Account Number",
              desc: "Returns the account number."
            }, {
              name: "Account Money",
              desc: "Returns the monetary amount within the account."
            }, {
              name: "Account Token",
              desc: "Returns the account's token."
            }
          ]
        }
      ],
      customers:[
        {
          parameters : [
            {
              name : "Customers",
              version : "1.0"
            }
          ],
          uri: Head + "/v1/customers/customer_number",
          methods : [
            {
              name: "Customer Name",
              desc: "Returns the customer's name."
            }, {
              name: "Customer ID",
              desc: "Returns the customer's ID."
            }
          ]
        },
        {
          parameters : [
            {
              name : "Customers",
              version : "2.0"
            }
          ],
          uri : Head + "/v2/customers/customer_number",
          methods: [
            {
              name: "Customer Name",
              desc: "Returns the customer's name."
            }, {
              name: "Customer ID",
              desc: "Returns the customer's ID."
            }, {
              name: "Customer Email",
              desc: "Returns the customer's email."
            }
          ]
        }
      ]
    }
    ]
  };

ng-repeat (just the right-hand tabs) ng-repeat (仅右侧选项卡)

<div class="col-md-9">
    <div class="tab-content">
      <div ng-repeat="(key, data) in apiList[0]" class="tab-pane active" id="tab{{$index}}">
        <div ng-repeat="api in apiList[0][key]">
          <div class="panel panel-info" id="panel{{$index}}">
            <div class="panel-heading">
              <h4 class="panel-title">
                <a data-toggle="collapse" data-target="#collapse{{key}}{{$index}}" class="collapsed">
                  {{api.uri}}<i class="newTab" ng-click="apiTab(api)">(Open in new tab)</i>
                </a>
              </h4>
            </div>
            <div id="collapse{{key}}{{$index}}" class="panel-collapse collapse">
              <div class="panel-body">
                <table class="table">
                  <tr ng-repeat="method in api.methods">
                    <td>{{method.name}}</td>
                    <td>{{method.desc}}</td>
                  </tr>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
  </div>
</div>

The following code is what I originally had, before trying to crunch it down more 以下代码是我最初拥有的代码,然后尝试进一步压缩

<div class="col-md-9" style="display:none">
          <div class="tab-content">

            <!-- Accounts -->

            <div class="tab-pane active" id="tab0">
              <div ng-repeat="api in apiList[0].accounts">
                <div class="panel panel-info" id="panel0">
                  <div class="panel-heading">
                    <h4 class="panel-title">
                      <a data-toggle="collapse" data-target="#collapseAccountsV{{$index}}" class="collapsed">
                        {{api.uri}}
                      </a>
                      <i class="newTab" ng-click="apiTab(api)">(Open in new tab)</i>
                    </h4>
                  </div>
                  <div id="collapseAccountsV{{$index}}" class="panel-collapse collapse">
                    <div class="panel-body">
                      <table class="table">
                        <tr ng-repeat="method in api.methods">
                          <td>{{method.name}}</td>
                          <td>{{method.desc}}</td>
                        </tr>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <!-- Customers -->

            <div class="tab-pane" id="tab1">
              <div ng-repeat="api in apiList[0].customers">
                <div class="panel panel-info" id="panel1">
                  <div class="panel-heading">
                    <h4 class="panel-title">
                      <a data-toggle="collapse" data-target="#collapseCustomersV{{$index}}" class="collapsed">
                        {{api.uri}}<i class="newTab" ng-click="apiTab(api)">(Open in new tab)</i>
                      </a>
                    </h4>
                  </div>
                  <div id="collapseCustomersV{{$index}}" class="panel-collapse collapse">
                    <div class="panel-body">
                      <table class="table">
                        <tr ng-repeat="method in api.methods">
                          <td>{{method.name}}</td>
                          <td>{{method.desc}}</td>
                        </tr>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <!-- Other -->
            <div class="tab-pane fade" id="tab3">
              <!-- TBA -->
            </div>
          </div>
        </div>

Noob mistake, everything works fine! 菜鸟的错误,一切正常! I was using my old code as the base outline on the same page and had set that old code to style="display:hidden" but this still meant that the ID's were apart of the DOM, hence why I couldn't change my tab's properly (duplicate/conflicting ID's). 我将旧代码用作同一页面上的基本大纲,并将旧代码设置为style="display:hidden"但这仍然意味着ID属于DOM,因此为什么我无法更改选项卡的正确(ID重复/冲突)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM