Javascript 在IE9中选择不工作的AngularJS默认选项
我的AngularJS应用程序中有一个表单,其中包含带有默认选项的下拉列表。我使用ng init和ng selected来实现这一点。它在Chrome中运行良好,但在InternetExplorer9中,当我第一次加载页面时,下拉列表中显示的是文本angularjs表达式,即“{showMethod(args)}”。当我去更改选项时,选项就在那里,它们应该在那里。只是最初表达式没有得到表达 以下是我的HTML代码:Javascript 在IE9中选择不工作的AngularJS默认选项,javascript,html,angularjs,internet-explorer,selected,Javascript,Html,Angularjs,Internet Explorer,Selected,我的AngularJS应用程序中有一个表单,其中包含带有默认选项的下拉列表。我使用ng init和ng selected来实现这一点。它在Chrome中运行良好,但在InternetExplorer9中,当我第一次加载页面时,下拉列表中显示的是文本angularjs表达式,即“{showMethod(args)}”。当我去更改选项时,选项就在那里,它们应该在那里。只是最初表达式没有得到表达 以下是我的HTML代码: <td> <div ng-if="var.method
<td>
<div ng-if="var.methods.length==0">NA</div>
<div ng-if="var.methods.length>0">
<select ng-init="selectedmethods[var.id]=defaultMethod(var.id,var.methods)" ng-model="selectedmethods[var.id]" >
<option ng-repeat="method in var.methods" value="{{method.id}}" ng-selected="isMethodSelected(var.id,method)">{{ showMethod(method,var.id)}}</option>
</select>
</div>
NA
{{showMethod(method,var.id)}
这是另一个ng重复的一部分。最初,我使用ng init将所选方法设置为该变量的默认方法。使用ng selected和一个名为isMethodSelected的方法,我通过检查selectedmethods对象来检查用户是否选择了该方法,如果没有,则检查该方法是否为defaut方法。 然后,我使用showMethod函数显示方法名称,我添加了showMethod函数以查看这是否有助于解决IE中的问题(它没有)。我以前只有表达式method.formattedMethodName 以下是我的JS代码的一部分:
$scope.isMethodSelected = function(varid,method) {
var sel = false;
if($scope.request.specsByVar.hasOwnProperty(varid) && $scope.request.specsByVar[varid].method.id==method.id) {
sel = true;
} else if(!$scope.request.specsByVar.hasOwnProperty(varid) && method.defaultMethod) {
sel = true;
}
return sel;
}
$scope.defaultMethod = function(varid,methods) {
var defaultMethod;
if($scope.request.specsByVar.hasOwnProperty(varid)) {
defaultMethod = $scope.request.specsByVar[varid].method.id;
} else {
for (var i = 0; i < methods.length; i++) {
if(methods[i].defaultMethod) {
defaultMethod = methods[i].id;
break;
}
}
}
return defaultMethod;
}
$scope.showMethod = function(method,varid) {
if(method) {
return method.formattedMethodName;
} else {
return $scope.selectedmethods[varid].formattedMethodName;
}
};
$scope.isMethodSelected=函数(变量,方法){
var-sel=假;
if($scope.request.specsByVar.hasOwnProperty(varid)&&$scope.request.specsByVar[varid].method.id==method.id){
sel=真;
}else if(!$scope.request.specsByVar.hasOwnProperty(varid)和&method.defaultMethod){
sel=真;
}
返回sel;
}
$scope.defaultMethod=函数(变量,方法){
var方法;
if($scope.request.specsByVar.hasOwnProperty(varid)){
defaultMethod=$scope.request.specsByVar[varid].method.id;
}否则{
对于(var i=0;i
这显然是一个IE问题。有人有解决办法吗
谢谢,
Olga我通过使用ng选项解决了这个问题:
<select ng-init="selectedmethods[var.id]=defaultMethod(var.id,var.methods)"
ng-model="selectedmethods[var.id]" title="{{ selectedmethods[var.id].formula }}"
ng-options="method.id as method.formattedMethodName for method in var.methods | filter:{active:true}">
</select>