"Bootstrap Angular UI Modal"未更新或显示字段数据。

15 浏览
0 Comments

"Bootstrap Angular UI Modal"未更新或显示字段数据。

我现在想做的就是从行数据中获取数据并将该行对应的对象属性显示到模态视图中的字段中。

此外,当提交按钮被点击时,编辑后的字段值应编辑对应的行数据。

我已经编写了下述代码,但是字段值没有显示人物对象属性,提交按钮也无法更新表格。

任何帮助将不胜感激。

HTML代码:


    
        

JSON to Table

 










First Name Last Name Age Nickname
{{person.FirstName}} {{person.LastName}} {{person.Age}} {{person.Nickname}}

Change Table Background Colour: Search For First Name in Table:

Search: First Name being searched for: {{searchText}}




First Names to be Searched For:
{{ person.FirstName }}

 

                                     

ModalView模板代码:

    

 

HTML Index Javascript文件代码:

var myTable = angular.module('myTable', ['ui.bootstrap']);
myTable.controller('tableCtrl', function($scope, $http, $uibModal) {
    $http.get("xxxxxxxx.json").success(function(response){
        $scope.people = response.People;
    });
    $scope.change = function(changeableData) {
        var modalInstance = $uibModal.open({
            templateUrl: 'modalView1.html',
            controller: ModalInstanceCtrl,
            size: 'lg',
            resolve: {
                person: function() {
                    return changeableData;
                }
            }
        });
    };
    var ModalInstanceCtrl = function($scope, $uibModalInstance, person) {
        $scope.FirstNameField = person.FirstName;
        $scope.LastNameField = person.LastName;
        $scope.AgeField = person.Age;
        $scope.NicknameField = person.Nickname;
        $scope.cancel = function () {
            $uibModalInstance.dismiss('cancel');
        };
        $scope.submitData = function () {
            console.log("Submitted Data");
            person.FirstName = $scope.FirstNameField;
            person.LastName = $scope.LastNameField;
            person.Age = $scope.AgeField;
            person.Nickname = $scope.NicknameField;
            $uibModalInstance.dismiss('submit');
        };
    };
});

非常感谢。我是StackOverflow新手,如果有做错的地方,请在评论中告诉我,我会更新的! 🙂

admin 更改状态以发布 2023年5月24日
0
0 Comments


应该是


更多信息请见ng-bind和ng-model之间的区别

我还做了一个在plnkr上使用ng-model有效的示例

0