在ngOptions中选择选项不会更新模型

时间:2018-02-27 10:23:29

标签: javascript angularjs angular1.6

我有一个稍微复杂的对象结构:

$scope.items = 
[
 {
   name: 'something',
   complexObject:
     {
        number: 1,
        id: 12345
     }
 },
  …more of those
]
$scope.selectedItem = $scope.items[0];

现在我想创建一个这样的下拉框:

<select 
   ng-options="item as item.complexObject.number for item in items track by items.complexObject.id" 
   ng-model="selectedItem">

当我使用其他项目更新selectedItem时,相应的数字会显示在下拉框中。但是当我从框中选择一个项目时,selectedItem不会更新。我注意到的是,我选择的所有选项都会在DOM中获得“选中”标记。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

The size of BLOB/TEXT data inserted in one transaction is greater than 10% of redo log size. Increase the redo log size using innodb_log_file_size.
var app = angular.module("Profile", [] );
                app.controller("ProfileCtrl", function($scope) {
                        $scope.items = 
                                [
                                 {
                                   name: 'something',
                                   complexObject:
                                     {
                                        number: 1,
                                        id: 12345
                                     }
                                 },
                                 {
                                   name: 'something',
                                   complexObject:
                                     {
                                        number: 2,
                                        id: 12345
                                     }
                                 },
                                ]
                        $scope.selectedItem     = {}
                        $scope.selectedItem['val'] = $scope.items[0];
                        $scope.get_info         = function(){
                                alert('Selected Row number "'+JSON.stringify($scope.selectedItem['val'])+'"')
                        }
                })