【发布时间】:2019-07-24 12:00:54
【问题描述】:
这是一个基本查询,但由于某种原因失败并需要帮助。
<select> 在尝试编辑实体时未填充值。它应该显示从 db 为该属性返回的值,但它没有,我也有ng-model。我相信它应该显示捐赠者的价值,但它显示为空白。还尝试使用ng-model = userDTO.memberType.description。
我哪里出错了?
<select
name="memberType"
class="form-control"
ng-model="userDTO.memberType"
ng-options="mt.description for mt in mtList">
</select>
控制器代码:
userService.findUserWithContactAndAddress($stateParams.user).then(
function(response) {
$scope.userDTO = response;
console.log("<<FullUserDetails>>:", response);
});
服务响应
<<FullUserDetails>>:
{id: 77,
donorType: {
id: 2,
desc: "Organization"
}
memberType: {
id: 4,
description: "Donor",
$$hashKey: "object:45"
},
$$hashKey: "object:44"
}
为了澄清,我确实从 db 中获得了完整的值列表,但是在 editUser 函数时为特定用户选择的值不会填充,而是 MemberType 是空白的。希望清楚。
$scope.mtList 返回
MemberTypes :
0: {id: 2, description: "CMA Member", $$hashKey: "object:96"}
1: {id: 4, description: "Donor", $$hashKey: "object:97"}
2: {id: 3, description: "Employee", $$hashKey: "object:98"}
3: {id: 6, description: "Other", $$hashKey: "object:99"}
4: {id: 1, description: "Trustee", $$hashKey: "object:100"}
5: {id: 5, description: "Volunteer", $$hashKey: "object:101"}
length: 6
__proto__: Array(0)
【问题讨论】:
-
$scope.mtList的内容是什么? -
我建议您在问题中添加新信息作为 cmets 或编辑。不是新的答案。
-
$scope.mtList的描述有问题。__proto__应该显示Array(6)。<<FullUserDetails>>缺少逗号。这些值是不可信的。 -
你能创建一个PLNKR 来重现问题吗?
-
它适用于 ... ng-options="mt as mt.description for mt in mtList track by mt.id"
标签: angularjs select ng-options