选择使用ng-options中的值不会填充

问题描述 投票:0回答:1

这是一个基本查询,但由于某种原因失败并需要帮助。

尝试编辑实体时,<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)
angularjs select ng-options
1个回答
0
投票

使用select表达式的select as形式:

<select     
    name="memberType"
    class="form-control"
    ng-model="userDTO.memberType"
    ̶n̶g̶-̶o̶p̶t̶i̶o̶n̶s̶=̶"̶m̶t̶.̶d̶e̶s̶c̶r̶i̶p̶t̶i̶o̶n̶ ̶f̶o̶r̶ ̶m̶t̶ ̶i̶n̶ ̶m̶t̶L̶i̶s̶t̶"̶
    ng-options="mt as mt.description for mt in mtList">                           
</select>

有关更多信息,请参阅AngularJS ng-options API Reference - select as

© www.soinside.com 2019 - 2024. All rights reserved.