2015-01-28 4 views
0

У меня есть переменная $ scope.uses (я бросил ее ниже). Изнутри «ng-repeat =» (key, val) in uses », Я не знаю, чтобы получить доступ к атрибутам в повторе. Я создаю страницу вкладок (по одному для каждого« урожая »), каждый . с таблицей рядов расходов (I потребуется вложенные нг-повторить один раз я понять, как получить доступ к атрибутам)AngularJS: доступ к атрибутам в ng-повторе

---- UPDATE: это мое мнение:

<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> 

- --end UPDATE

{ 
    "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 
    } 
    ] 
} 
+0

Пожалуйста, поделитесь HTML код, где вы пытаетесь использовать 'нг-repeat'. –

+0

добавленный код просмотра по запросу – jgravois

+0

Я не могу видеть код? –

ответ

0

(key, val) используется в ретрансляторах для заполнения выпадающих тха t требует значения и имени, например. Для этого сценария вам нужно сделать ng-repeat="item in corn", чтобы вы могли использовать весь набор свойств каждой «кукурузы».

Если у вас есть зерно массива внутри объекта использует затем ng-repeat="corn in uses.corn"

Я думаю, что вы относитесь к свойствам, когда вы говорите атрибуты.

Атрибуты, как этот: <corn crop="corn"> но когда вы делаете {'corn':{ 'crop' : 'corn' }} Crop это свойство объекта кукурузного

Смежные вопросы