我有一個動態生成的表。每行包含一個select
(又名下拉菜單)和一個checkbox
。在用ngRepeat創建的動態表中引用DOM元素
在select
的變化,我想另外更改屬性爲checkbox
,但我不能確定如何從ng-change
函數引用checkbox
。
這裏是一個動態的HTML表:
</table>
<tr ng-repeat = "(index, item) in items">
<td >
<select ng-model="item.myDropDown" ng-change="dropDownChange()">
<option value="A"> A </option>
<option value="B"> B </option>
</select>
</td>
<td>
<input type="checkbox" ng-model="item.myCheckbox" value="unchecked" disabled='disabled'/>
</td>
</tr>
</table>
現在,我嘗試使用引用上改變這些元素:
myApp.controller('myController', function($scope) {
$scope.dropdownChange = function() {
console.debug(this.item.toDoDropdown); //I am able to reference the select-option values
document.getElementById(this.item.myCheckbox).checked = true; //This is placeholder code to signify my intent at referencing the checkbox
}
}
在我看來,該checkbox
不在scope
此ngChange
函數,但是我不確定如何解決這個問題。 此外,我試圖給每個錶行自己的控制器建議在我的互聯網旅行,命名爲here;這是不錯的做法嗎?
也許我失去了一些東西,但'document.getElemntById(this.item.myCheckBox)'不應該返回的元素,它具有沒有id屬性和值'this.item.myCheckBox'不是一個id選擇器 – Nindaff
你是完全正確的。我用這個作爲佔位符來顯示我訪問複選框的意圖。我將編輯。 – eric