Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS:在ng repeat中访问属性_Angularjs - Fatal编程技术网

AngularJS:在ng repeat中访问属性

AngularJS:在ng repeat中访问属性,angularjs,Angularjs,我有一个变量$scope.uses,我在下面转储了它。从ng repeat=key的内部,val in使用,我不知道如何访问repeat中的属性。我正在为每种作物创建一个标签页,每个标签页都有一个费用表,一旦我知道如何访问这些属性,我就需要一个嵌套的ng repeat --更新:这是我的观点: <div> <fieldset> <tabset> <!-- REPEAT FOR EACH CROP SELECTED-->

我有一个变量$scope.uses,我在下面转储了它。从ng repeat=key的内部,val in使用,我不知道如何访问repeat中的属性。我正在为每种作物创建一个标签页,每个标签页都有一个费用表,一旦我知道如何访问这些属性,我就需要一个嵌套的ng repeat

--更新:这是我的观点:

<div>
    <fieldset>
    <tabset>
    <!-- REPEAT FOR EACH CROP SELECTED-->
    <tab ng-repeat="(key, val) in uses" heading={{key|capitalize}}>
      <table class="table table-striped rowed">
        <tbody>
        <tr>
          <th class="text-left" style="width:20%;">&nbsp;</th>
          <th class="text-left" colspan="4">ACRE</th>
          <th class="text-left" colspan="4">
            {{key.acres|number:1}} ACRE TOTALS
          </th>
        </tr>

        <tr>
          <td style="width:10%;" class="text-right">&nbsp;</td>
          <td class="text-center" style="width:10%;">ARM</td>
          <td class="text-center" style="width:10%;">
            {{loan.distributor}}
          </td>
          <td class="text-center" style="width:10%;">Other</td>
          <td class="text-center" style="width:10%;">Total</td>
          <td class="text-center" style="width:10%;">ARM</td>
          <td class="text-center" style="width:10%;">
            {{loan.distributor}}
          </td>
          <td class="text-center" style="width:10%;">Other</td>
          <td class="text-center" style="width:10%;">Total</td>
        </tr>

        <tr ng-if="uses.expenses.length == 0">
          <td colspan="9">
            <strong>No expenses recorded.</strong>
          </td>
        </tr>

        <tr ng-repeat="c in x.expenses">
          <td>
            {{c.expense|capitalize}}
          </td>
          <td class="text-right" ng-class="gtZero(c.arm)">
            {{c.arm|flexCurrency:2}}
          </td>
          <td class="text-right" ng-class="gtZero(c.dist)">
            {{c.dist|flexCurrency:2}}
          </td>
          <td class="text-right" ng-class="gtZero(c.other)">
            {{c.other|flexCurrency:2}}
          </td>
          <td class="text-right" ng-class="gtZero(c.peracre)">
            {{c.peracre = c.arm * 1 + c.dist * 1 + c.other * 1|flexCurrency:2}}
          </td>
          <td class="text-right" ng-class="gtZero(c.calc_arm)">
            {{c.calc_arm|flexCurrency:0}}
          </td>
          <td class="text-right" ng-class="gtZero(c.calc_dist)">
            {{c.calc_dist|flexCurrency:0}}
          </td>
          <td class="text-right" ng-class="gtZero(c.calc_other)">
            {{c.calc_other|flexCurrency:0}}
          </td>
          <td class="text-right" ng-class="gtZero(c.calc_total)">
            {{c.calc_total|flexCurrency:0}}
          </td>
        </tr>

        <tr class="success">
          <td>TOTAL</td>
          <td ng-class=gtZero(x.totals.acre_arm)>
            {{x.totals.acre_arm  | flexCurrency:2 }}
          </td>
          <td ng-class=gtZero(x.totals.acre_dist)>
            {{x.totals.acre_dist | flexCurrency:2 }}
          </td>
          <td ng-class=gtZero(x.totals.acre_other)>
            {{x.totals.acre_other | flexCurrency:2 }}
          </td>
          <td ng-class=gtZero(x.totals.acre_total)>
            {{x.totals.acre_loan | flexCurrency:2 }}
          </td>
          <td ng-class=gtZero(x.totals.loan_arm)>
            {{x.totals.arm | flexCurrency:0 }}
          </td>
          <td ng-class=gtZero(x.totals.loan_dist)>
            {{x.totals.dist | flexCurrency:0 }}
          </td>
          <td ng-class=gtZero(x.totals.loan_other)>
            {{x.totals.other | flexCurrency:0 }}
          </td>
          <td ng-class=gtZero(x.totals.loan_total)>
            {{x.totals.loan | flexCurrency:0 }}
          </td>
        </tr>

        </tbody>
      </table>
    </tab>
    </tabset>
    </fieldset>
    <!--<pre>{{farmExpenses | json}}</pre>-->
    <pre>{{uses | json}}</pre>
    </div>
键,val在中继器中用于填充下拉列表,例如需要值和名称。对于此场景,您需要在corn中执行ng repeat=item,以便能够使用每个“corn”的整个属性集

如果对象uses中有数组corn,则ng repeat=corn in uses.corn

我认为当你说属性时,你指的是属性


属性是这样的:但是当你做{'corn':{'crop':'corn'}}时,crop是对象corn的一个属性

请在你试图使用ng-repeat的地方共享HTML代码。作为请求添加了查看代码。我看不到代码?很抱歉,因为我必须格式化它,所以延迟了
{
  "corn": [
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Fertilizer",
      "arm": 0,
      "dist": 164.97,
      "other": 0,
      "peracre": 164.97,
      "calc_arm": 0,
      "calc_dist": 57310.578,
      "calc_other": 0,
      "calc_total": 57310.578
    },
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Seed",
      "arm": 0,
      "dist": 0,
      "other": 115,
      "peracre": 115,
      "calc_arm": 0,
      "calc_dist": 0,
      "calc_other": 39951,
      "calc_total": 39951
    },
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Fungicide",
      "arm": 0,
      "dist": 0,
      "other": 0,
      "peracre": 0,
      "calc_arm": 0,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 0
    },
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Herbicide",
      "arm": 0,
      "dist": 32.94,
      "other": 0,
      "peracre": 32.94,
      "calc_arm": 0,
      "calc_dist": 11443.356,
      "calc_other": 0,
      "calc_total": 11443.356
    },
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Insecticide",
      "arm": 0,
      "dist": 0,
      "other": 0,
      "peracre": 0,
      "calc_arm": 0,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 0
    },
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Custom",
      "arm": 18,
      "dist": 0,
      "other": 0,
      "peracre": 18,
      "calc_arm": 6253.2,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 6253.2
    },
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Fuel",
      "arm": 40,
      "dist": 0,
      "other": 0,
      "peracre": 40,
      "calc_arm": 13896,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 13896
    },
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Labor",
      "arm": 20,
      "dist": 0,
      "other": 0,
      "peracre": 20,
      "calc_arm": 6948,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 6948
    },
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Repairs",
      "arm": 20,
      "dist": 0,
      "other": 0,
      "peracre": 20,
      "calc_arm": 6948,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 6948
    },
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Insurance",
      "arm": 0,
      "dist": 0,
      "other": 0,
      "peracre": 0,
      "calc_arm": 0,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 0
    },
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Harvesting",
      "arm": 0,
      "dist": 0,
      "other": 0,
      "peracre": 0,
      "calc_arm": 0,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 0
    },
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Misc Acre",
      "arm": 20,
      "dist": 0,
      "other": 0,
      "peracre": 20,
      "calc_arm": 6948,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 6948
    },
    {
      "crop": "corn",
      "acres": 347.4,
      "expense": "Living Expenses",
      "arm": 60,
      "dist": 0,
      "other": 0,
      "peracre": 60,
      "calc_arm": 20844,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 20844
    }
  ],
  "soybeans": [
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Fertilizer",
      "arm": 0,
      "dist": 26.5,
      "other": 0,
      "peracre": 26.5,
      "calc_arm": 0,
      "calc_dist": 15377.95,
      "calc_other": 0,
      "calc_total": 15377.95
    },
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Seed",
      "arm": 0,
      "dist": 0,
      "other": 60,
      "peracre": 60,
      "calc_arm": 0,
      "calc_dist": 0,
      "calc_other": 34818,
      "calc_total": 34818
    },
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Fungicide",
      "arm": 0,
      "dist": 12.5,
      "other": 0,
      "peracre": 12.5,
      "calc_arm": 0,
      "calc_dist": 7253.75,
      "calc_other": 0,
      "calc_total": 7253.75
    },
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Herbicide",
      "arm": 0,
      "dist": 20.06,
      "other": 0,
      "peracre": 20.06,
      "calc_arm": 0,
      "calc_dist": 11640.818,
      "calc_other": 0,
      "calc_total": 11640.818
    },
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Insecticide",
      "arm": 0,
      "dist": 10.67,
      "other": 0,
      "peracre": 10.67,
      "calc_arm": 0,
      "calc_dist": 6191.801,
      "calc_other": 0,
      "calc_total": 6191.801
    },
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Custom",
      "arm": 22,
      "dist": 0,
      "other": 0,
      "peracre": 22,
      "calc_arm": 12766.6,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 12766.6
    },
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Fuel",
      "arm": 30,
      "dist": 0,
      "other": 0,
      "peracre": 30,
      "calc_arm": 17409,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 17409
    },
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Labor",
      "arm": 20,
      "dist": 0,
      "other": 0,
      "peracre": 20,
      "calc_arm": 11606,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 11606
    },
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Repairs",
      "arm": 10,
      "dist": 0,
      "other": 0,
      "peracre": 10,
      "calc_arm": 5803,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 5803
    },
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Insurance",
      "arm": 0,
      "dist": 0,
      "other": 14.35,
      "peracre": 14.35,
      "calc_arm": 0,
      "calc_dist": 0,
      "calc_other": 8327.305,
      "calc_total": 8327.305
    },
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Harvesting",
      "arm": 0,
      "dist": 0,
      "other": 0,
      "peracre": 0,
      "calc_arm": 0,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 0
    },
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Misc Acre",
      "arm": 20,
      "dist": 0,
      "other": 0,
      "peracre": 20,
      "calc_arm": 11606,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 11606
    },
    {
      "crop": "soybeans",
      "acres": 580.3,
      "expense": "Living Expenses",
      "arm": 43,
      "dist": 0,
      "other": 0,
      "peracre": 43,
      "calc_arm": 24952.9,
      "calc_dist": 0,
      "calc_other": 0,
      "calc_total": 24952.9
    }
  ]
}