【问题标题】:UI Grid refresh in AngularAngular中的UI网格刷新
【发布时间】:2016-04-28 13:03:09
【问题描述】:

从不同的控制器打开一个模式弹出窗口。在关闭模式弹出窗口时,我会做一些事情,我想将数据传输到另一个控制器,该控制器填充 UI 网格并绑定到 $scope.searchResultsGridOptions

所以在我的ABCCtrl.js 文件中:

关闭模式时,我会这样做:

$("#iConfirmationModal").on('hidden.bs.modal', function () {
    $state.go('transaction.search.results', {});
    //I close all the modals
    $uibModalStack.dismissAll();
    //I get the stored search criteria 
    var searchResultsParam = TransactionDataServices.getSavedSearchParams();


    //Using them I hit the web service again and get the data to reload the UI Grid 
    TransactionServices.getTransactionAdvSearchResults(searchResultsParam).then(function (result) {

            //I got the result
            console.log(result);
            /Now I want to reload the grid with this data , but the grid scope object which binds to this , is in separate controller
            searchResultsGridOptions.data = result;
        });
    });

在 DEFCtrl.js 中

我有

    getSearchResultsGridLayout: function (gridOptions, uiGridConstants, datas) {
        gridOptions.multiSelect = false;
        //  gridOptions.data.length = 0;
        // gridOptions.data = '';
        gridOptions.data = datas;
        console.log("Grid Data ");
        console.log(datas);
        console.log(gridOptions.data);
        angular.element(document.getElementsByClassName('grid')[0]).css('height', '0px');
        // console.log(datas.length);
        return gridOptions;
    }

但我如何仅在模式关闭时才更改数据?

其余时间不应该刷新 Grid 吗?

或者,

在关闭模式时有什么办法,而不是简单地使用$state.for()返回状态并查看以前未刷新的数据,我可以看到刷新的数据?

【问题讨论】:

    标签: javascript jquery angularjs twitter-bootstrap


    【解决方案1】:

    您好,我认为您不需要在“ABCCtrl”控制器中调用“TransactionServices.getTransactionAdvSearchResults()”,但您必须在“DEFCtrl”控制器中调用它。

    你需要想办法将“ABCCtrl”中提取的“searchResultsParam”传递给“DEFCtrl”。

    您可以使用ui-router state parameters。您可以在“transaction.search.results”状态中指定一个参数,如下所示:

    .state('transaction.search.results', {
        ...
        params: {
            searchResultsParam: null
        }
       ...
    })
    

    并在“ABCCtrl”中将它传递给状态:

    $("#iConfirmationModal").on('hidden.bs.modal', function () {
        //I close all the modals
        $uibModalStack.dismissAll();
        //I get the stored search criteria 
        var searchResultsParam = TransactionDataServices.getSavedSearchParams();
        $state.go('transaction.search.results', {searchResultsParam: searchResultsParam});
    

    然后,您可以在“DEFCtrl”中读取它并调用“TransactionServices.getTransactionAdvSearchResults()”方法。

    【讨论】:

      猜你喜欢
      • 2015-03-28
      • 2017-06-10
      • 2013-05-04
      • 2019-01-06
      • 2017-04-17
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多