Select元素在AngularJS中不显示收到的值
由于某些原因,我无法理解,我的select元素(带有Select元素在AngularJS中不显示收到的值,angularjs,html-select,Angularjs,Html Select,由于某些原因,我无法理解,我的select元素(带有ng repeat)没有显示从数据库检索到的值 源标记是: <select class="form-control" id="Test_Method_Select_{{$index}}" ng-model="One_Source.Test_Method_Code" style="width:150px"> <option ng-repeat="One_Method
ng repeat
)没有显示从数据库检索到的值
源标记是:
<select class="form-control"
id="Test_Method_Select_{{$index}}"
ng-model="One_Source.Test_Method_Code"
style="width:150px">
<option ng-repeat="One_Method in One_Source.Formatted_Test_Methods_List" value="{{One_Method.Value}}">
{{One_Method.Value}} - {{One_Method.Name}}
</option>
</select>
<select class="form-control ng-pristine ng-valid ng-not-empty ng-touched"
id="Test_Method_Select_1"
ng-model="One_Source.Test_Method_Code"
style="width:150px">
<option value="? number:26 ?"></option>
<!-- ngRepeat: One_Method in One_Source.Formatted_Test_Methods_List -->
<option ng-repeat="One_Method in One_Source.Formatted_Test_Methods_List" value="103" class="ng-binding ng-scope">103 - LC-MS-MS</option>
<!-- end ngRepeat: One_Method in One_Source.Formatted_Test_Methods_List -->
<option ng-repeat="One_Method in One_Source.Formatted_Test_Methods_List" value="26" class="ng-binding ng-scope">26 - Pesticides - GCMS</option>
<!-- end ngRepeat: One_Method in One_Source.Formatted_Test_Methods_List -->
<option ng-repeat="One_Method in One_Source.Formatted_Test_Methods_List" value="29" class="ng-binding ng-scope">29 - Aldicarb - LLE,GCMS</option>
<!-- end ngRepeat: One_Method in One_Source.Formatted_Test_Methods_List -->
</select>
{{One_Method.Value}}-{{One_Method.Name}
生成的(AngularJS)标记为:
<select class="form-control"
id="Test_Method_Select_{{$index}}"
ng-model="One_Source.Test_Method_Code"
style="width:150px">
<option ng-repeat="One_Method in One_Source.Formatted_Test_Methods_List" value="{{One_Method.Value}}">
{{One_Method.Value}} - {{One_Method.Name}}
</option>
</select>
<select class="form-control ng-pristine ng-valid ng-not-empty ng-touched"
id="Test_Method_Select_1"
ng-model="One_Source.Test_Method_Code"
style="width:150px">
<option value="? number:26 ?"></option>
<!-- ngRepeat: One_Method in One_Source.Formatted_Test_Methods_List -->
<option ng-repeat="One_Method in One_Source.Formatted_Test_Methods_List" value="103" class="ng-binding ng-scope">103 - LC-MS-MS</option>
<!-- end ngRepeat: One_Method in One_Source.Formatted_Test_Methods_List -->
<option ng-repeat="One_Method in One_Source.Formatted_Test_Methods_List" value="26" class="ng-binding ng-scope">26 - Pesticides - GCMS</option>
<!-- end ngRepeat: One_Method in One_Source.Formatted_Test_Methods_List -->
<option ng-repeat="One_Method in One_Source.Formatted_Test_Methods_List" value="29" class="ng-binding ng-scope">29 - Aldicarb - LLE,GCMS</option>
<!-- end ngRepeat: One_Method in One_Source.Formatted_Test_Methods_List -->
</select>
103-LC-MS-MS
26-杀虫剂-GCMS
29-涕灭威-LLE,GCMS
该元素不显示26-杀虫剂-GCMS,即使显示的值是接收到的值
编辑
根据Markus的建议,源标记现在看起来如下所示:
<select class="form-control"
id="Test_Method_Select_{{$index}}"
ng-model="One_Source.Test_Method_Code"
style="width:150px"
ng-options="item.Value as (item.Value + '-' + item.Name) for item in One_Source.Formatted_Test_Methods_List">
</select>
仍然没有显示选定的值(注意:我在元素前面添加了
模型中的值:{{One_Source.Test_Method_code}}
,并显示了正确的值,但没有显示在select元素中)。您应该看看NgOptions。下面是一个工作示例,我通过设置$scope.One\u Source.Test\u Method\u code
angular.module(“app”,[]).controller(“myCtrl”,函数($scope){
$scope.One_Source={};
$scope.One\u Source.Formatted\u Test\u Methods\u List=[
{
价值:103,
名称:“LC-MS-MS”
},
{
价值:26,
名称:“杀虫剂-GCMS”
},
{
价值:29,
名称:“涕灭威-LLE,GCMS”
}
];
$scope.One_Source.Test_Method_Code=29;
});代码>
Markus,感谢您的快速响应。我需要模型只包含值29
(即没有-Aldicarb-LLE,GCMS
。这会是结果吗?如果不是,我应该如何设置ng选项来实现这一点?Markus,我测试了你的建议,仍然是值(在你的示例中为29)未显示。我将使用源标记的新代码更新问题(2分钟…。@FDavidov检查One_source.Test_Method_代码中的值是否为numberMarcus,一句话是“宾果”。问题是值字段是字符串。只要我将其包装成Number()
函数所有功能都可以根据需要工作。谢谢您,先生!!!!@FDavidov NP,“宾果”嘿嘿