gpt4 book ai didi

angularjs - 识别 ng-repeat 项上 ng-change 的事件源

转载 作者:行者123 更新时间:2023-12-02 22:25:46 25 4
gpt4 key购买 nike

如果我有......

<ul>
<li ng-repeat="s in collection">
<select ng-change="update()">
<option></option>
</select>
</li>
</ul>

如何获取对引发 update() 调用的特定选择的引用?

最佳答案

像这样&heres fiddle :

<div ng-controller="MyCtrl">
<ul>
<li ng-repeat="s in collection">
Hello I am {{s.name}} & these are my options
<select ng-options="o as o for o in s.options" ng-model="s.selectedOption" ng-change="optionChanged()">
</select>
</li>
</ul>
</div>

<script>
var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
$scope.collection = [
{'name':'one', 'value':1, 'options':['A','B']},
{'name':'two', 'value':2, 'options':['C','D']}
];

$scope.optionChanged = function(){
console.debug(this.s.selectedOption);
}
}
</script>

关于angularjs - 识别 ng-repeat 项上 ng-change 的事件源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17656374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com