0

我有一张桌子,上面有电视节目数据。我用它填充表格,dir-paginate/ng-repeat我可以单击一行来打开一个模式以便能够编辑显示,但 ng-model 数据没有加载到该模式内的文本框中。

<tr id='schedule_row' class='hover_click_cell' dir-paginate='tv_show in tv_shows | orderBy:sortType:sortReverse | itemsPerPage:10'>
<td class='center_text clickable_cell cell_width' ng-click='alter_show(tv_show)'>{{tv_show.show_name}}</td>

单击时,它会调用该函数alter_show()

$scope.alter_show = function(show)
{
    $scope.edit_show = show;
    var modalInstance = $uibModal.open    ({    animation: $controller.animationsEnabled,
                                                ariaLabelledBy: 'modal-title',
                                                ariaDescribedBy: 'modal-body',
                                                templateUrl: 'edit_tv_show.html',
                                                controller: 'EditTvShowCtrl',
                                                controllerAs: '$controller',
                                                size: 'sm',
                                                backdrop: 'static',
                                                keyboard: false
                                        });

    modalInstance.result.then(function (action) 
    {

    }, 
    function () {
    });
}

传递的数据在 JSON 格式中如下所示:

{"watched":false,"id":1,"show_name":"The Walking Dead","season":1,"episode":1,"season_episode":"Season 1, Episode 1","$$hashKey":"object:4"}

我传入显示详细信息并将其设置为$scope.edit_show对象。传递的数据不是空的,但是当打开模式时,不会填充文本框。这些是输入框:

$scope.edit_show = {
    show_name: '',
    season: 0,
    episode: 0,
    watched: 0
};

<div class='form-group'>
<label for='show_name'>Show Name:</label>
<input type='text' class='form-control' id='edit_show_name' ng-model='edit_show.show_name'>
</div>

<div class='form-group'>
<label for='season'>Season:</label>
<input type='number' class='form-control' id='edit_season' ng-model='edit_show.season'>
</div>

我怎样才能让它用已单击行的详细信息填充文本框?

4

1 回答 1

0

我已经设法使用 modalInstance 的解析来解决它。

$scope.alter_show = function(show)
{
    var modalInstance = $uibModal.open    ({    animation: $controller.animationsEnabled,
                                                ariaLabelledBy: 'modal-title',
                                                ariaDescribedBy: 'modal-body',
                                                templateUrl: 'edit_tv_show.html',
                                                controller: 'EditTvShowCtrl',
                                                controllerAs: '$controller',
                                                size: 'sm',
                                                backdrop: 'static',
                                                keyboard: false,
                                                resolve: { tv_show : function() { return show; } }
                                        });

    modalInstance.result.then(function (action) 
    {

    }, 
    function () {
    });
}

angular.module('ui.bootstrap').controller('EditTvShowCtrl', function ($uibModalInstance, $scope, tv_show) 
{
    var $controller = this;

    $scope.edit = tv_show;
});
于 2017-04-26T12:51:36.683 回答