繁体   English   中英

在调用填充详细信息网格的方法之前,如何从填充的下拉列表中获取信息?

[英]How do get information from a populated dropdownlist before calling a method to fill the details grid?

这样做的正确方法是什么? 这是一个又一个的语句,但是由于javascript是异步的,我想在调用第二个函数时$ score.lastItem不存在? 那么我是否将此第二个函数放在第一个的回调中?

 //1st Call this on inital load to populate Congresses dropdownlist
ccResource.query(function (data) {
    $scope.ccList.length = 0;
    angular.forEach(data, function (ccData) {
        $scope.ccList.push(ccData);
    })

    $scope.lastItem = $scope.ccList[$scope.ccList.length - 1];
});

//2nd after populating $scope.lastItem run this to populate grid on initial load (using id from selected item in dropdownlist)
cgResource.query({ id: $scope.lastItem.congressNumber }, function (data) {
    $scope.usersList = data;
});

//ngGrid
$scope.userGrid = {
    data: 'usersList',
    multiSelect: false,
    selectedItems: $scope.selectedUsers,
    enableColumnResize: false,
    columnDefs: [
        { field: 'firstname', displayName: 'First Name', width: '25%' },
        { field: 'lastname', displayName: 'Last Name', width: '25%' }
    ]
};

是的你可以

//1st Call this on inital load to populate Congresses dropdownlist
ccResource.query(function (data) {
    $scope.ccList.length = 0;
    angular.forEach(data, function (ccData) {
        $scope.ccList.push(ccData);
    })

    $scope.lastItem = $scope.ccList[$scope.ccList.length - 1];

    //2nd after populating $scope.lastItem run this to populate grid on initial load (using id from selected item in dropdownlist)
    cgResource.query({
        id: $scope.lastItem.congressNumber
    }, function (data) {
        $scope.usersList = data;
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM