2014-11-24 45 views
0

我有一個< tr>,它通過ng-repeat來控制以傳遞一個對象。其中一個< td>元素是一個文本字段,並且我在$ scope上有一個函數,它返回文本的行數。現在,在一個又一個< TD>同一行中,我想我必須在文本框線條添加儘可能多的選擇框,所以我想是這樣的:AngularJS根據其他td修改td

<table> 
    <tr ng-repeat="variable in variables"> 
    <td> 
     <label for="varValues">Choices:</label> 
     <textarea class="form-control" ng-model="variable.extras" id="varValues" cols="40" rows="5">{{variable.extras}}</textarea> 
    </td> 
    <td> 
     <table> 
     <tr element-repeat="numberOfRowsForChoiceVariable(variable)"> 
      <select class="form-control" ng-options=""> 
      <option value="">-- Default Skill --</option> 
      </select> 
     </tr> 
     </table> 
    </td> 

我得到只是一個單一的< select>第二列中的元素。當我更改文本字段的內容時,如何使其重新評估?

+0

'numberOfRowsForChoiceVariable()'看起來像什麼? – isherwood 2014-11-24 21:10:24

+0

它根據變量中的行數返回我想要存在的數字選擇框.extras model – Scott 2014-11-25 18:33:20

+0

這個tr應該是一個循環正確次數的ng-repeat。但問題仍然存在,每當變量.extras更改時,如何重寫td元素? – Scott 2014-11-25 18:35:32

回答

0

您需要將您的數量值轉換爲數組。像這樣的東西應該做的:

$scope.getNumArray = function(num) { 
    return new Array(num); 
} 

你會使用這裏面numberOfRowsForChoiceVariable(variable)返回數組,而不是一個整數。

+0

我將它從element-repeat =「」更改爲numberOfRowsForChoiceVariable中的「ng-repeat =」x (變量)跟蹤由$ index「',它返回像你所顯示的數組。儘管在我的頁面上,我仍然只是獲得了一個select元素。 – Scott 2014-11-25 22:30:08