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

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

本文关键字:填充 下拉列表 获取 信息 方法 调用 详细信息 网格      更新时间:2023-09-26

正确的方法是什么?这是一个接一个的语句,但由于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;
    });
});