angularjs - 如何从 Angularjs 更新记录的下拉列表中获取选定值?
问题描述
我用 json 中的 angular js 填充了我的下拉列表。但是选择不适用于更新我无法获得选定的值。如何选择下拉列表中的选定项目?
//get single record by ID
$scope.getForUpdate = function (Branch) {
debugger
var getData = myService.getBrancheTypes();
getData.then(function (response) {
debugger
$scope.BrancheTypes = response.data;
}, function (error) {
console.log(error);
toastr.error("Error in getting records.");
});
debugger
$scope.Branch_ID = Branch.Branch_ID;
$scope.Branch_Name = Branch.Branch_Name;
$scope.Branch_Address = Branch.Branch_Address;
$scope.Branch_email = Branch.Branch_email;
$scope.Branch_Notes = Branch.Branch_Notes;
$scope.Branch_TimeFrom = new Date(moment(Branch.Branch_TimeFrom));
$scope.Branch_TimeTo = new Date(moment(Branch.Branch_TimeTo));
$scope.Branch_CreatedDate = new Date(moment(Branch.Branch_CreatedDate));
$scope.Branch_Manager = Branch.Branch_Manager;
$scope.Branch_TypeId = Branch.Branch_TypeId; // Branch.Branch_TypeId = 1
$scope.Branch_Type = $scope.BrancheTypes[Branch.Branch_Type]; // Object {BranchTypeId: 1, BranchTypeName: "Head Office", Branches: null}
$scope.Branch_Phone = Branch.Branch_Phone;
$scope.Branch_Fax = Branch.Branch_Fax;
$scope.saturday = Branch.saturday;
$scope.sunday = Branch.sunday;
$scope.monday = Branch.monday;
$scope.tuesday = Branch.tuesday;
$scope.wednesday = Branch.wednesday;
$scope.thursday = Branch.thursday;
$scope.friday = Branch.friday;
};
<select ng-model="Branch_Type">
<option value="{{field.BranchTypeId}}" ng-selected="true"
ng-repeat="field in BrancheTypes | orderBy:'BranchTypeId'">
{{field.BranchTypeName}}
</option>
</select>
这是调试时的值
解决方案
尝试将您的 html 更改为此
<select ng-model="selectedDevice"
ng-options="field.BranchTypeId as field.BranchTypeName for field in BrancheTypes | orderBy:'BranchTypeId'">
<option></option>
</select>
推荐阅读
- html - (HTML & CSS) 当用户按下“Enter”时如何执行一个动作
- input - 使用 nodejs 开发应用程序
- python - 如何识别python字典中的根节点?
- python - 如何修复“AttributeError:'JpegImageFile'对象没有属性'read'?
- python - 如何在 python 脚本退出时杀死我的线程(如果需要)?
- react-native - 如果 react native 调试器关闭,则 moment 返回无效日期
- android - 如何在android中以编程方式折叠和禁用折叠工具栏布局
- r - 无法通过 ggplot2 在 if 语句中创建 PDF
- python - 在 python 中使用 thunk、trampolines 和延续传递
- javascript - Redux:如何管理跨路由的冲突状态?