gpt4 book ai didi

angularjs - 通过 ng-click 选择选项在使用 AngularJS 的 chrome 浏览器中不起作用

转载 作者:行者123 更新时间:2023-12-04 16:44:32 24 4
gpt4 key购买 nike

我需要使用 ng-click 以便我可以传递三个参数并根据选择在我的本地 json 中进行设置。

<select>                                                             
<option id="" value="">--Select--</option>
<option ng-repeat="comparison in comparisons" ng-click="setSkillComparisonOperator(index,comparison.sid,comparison.name)"
ng-selected="comparison.sid == data.value.comparisonOperator.sid">{{comparison.name}}</option>
</select>

我可以使用它 ng-model 和 ng-change 如下。
<select ng-model="item" ng-options="o.id as o.id for o in list" ng-change="onFunction(item)">{{item}}</select>

在这种情况下,我不能传递如下三个参数。
<select ng-model="item" ng-options="o.id as o.id for o in list" ng-change="onFunction(o.id,o.name)">{{item}}</select>

最佳答案

最后,我找到了解决方案。

JS fiddle link

HTML 页面是

<div ng-app="miniapp">
<div ng-controller="Ctrl">
<select ng-model="selectedColor" ng-options="color as color.name for color in colors" ng-init="selectedColor = check(color1,colors)" ng-change="setColor(selectedColor)">
<option value="">Select A Color</option>
</select>
<br/>
<br/>
Color Id: <span ng-bind="colorId"></span>
<br/>
Color name: <span ng-bind="color"></span>
<br/>
Color shade: <span ng-bind="shade"></span>
<br/>
</div>
</div>

Javascript 是
var $scope;
var app = angular.module('miniapp', []);

function Ctrl($scope) {
$scope.colorId = 4;
$scope.shade = null;
$scope.color = null;
$scope.color1 = {name:'Red', value: 'red',id:2};
$scope.colors = [
{name:'Red', shade: 'white',id:1},
{name:'Orange', shade: 'red',id:2},
{name:'Yellow', shade: 'blue',id:3},
{name:'Green', shade: 'yellow',id:4},
{name:'Blue', shade: 'indigo',id:5},
{name:'Indigo', shade: 'violet',id:6},
{name:'Violet', shade: 'orange',id:7}
];
$scope.check =function(selectedColor,colors){
var i = null;
for(i in colors){
if(colors[i].id == selectedColor.id){
return colors[i];
}
}
};
$scope.setColor= function(color){
$scope.colorId = color.id;
$scope.shade = color.shade;
$scope.color = color.name;
};
};

关于angularjs - 通过 ng-click 选择选项在使用 AngularJS 的 chrome 浏览器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21051345/

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