更新AngularJs中的下拉列表

时间:2017-08-24 09:23:05

标签: javascript angularjs

我有正确加载我的下拉列表的AngulayJS标记。

<md-input-container ng-init="SchoolSavedSearches(39424,2,true)" 
                                    class="md-block" style="margin:0 !important;">
    <md-select ng-model="selectedSavedsearch" placeholder="Select a Saved Search" id="Md-select2">
        <md-option ng-value="s" ng-repeat="s in savedSearchList">{{s.title}}</md-option>
    </md-select>
</md-input-container>

同一页面上的一个操作是将另一个项目添加到上面的下拉列表中。现在我有下面的代码,我认为应该将下拉列表更新为与$scope.savedSearchList的绑定,并将其填充为插入新行后不久。

但是我遇到了问题,在调试时,我可以看到$scope.savedSearchList包含新添加的行,但是下拉列表没有反映这一点,除非我刷新同一页面。

我对AngularJs的理解是,下拉列表应该在函数$scope.SchoolSavedSearches(39424, 2, true)更新其绑定的$scope.savedSearchList时更新。

以下是我的代码:

插入新行

$scope.SaveSearch = function () {
if (localStorage.length > 0) {
    // get empno from localstorage json
    var empData = JSON.parse(localStorage.getItem(localStorage.key(0)));
    var empno = 0;
    // get all the keys
    var keys = Object.keys(empData);

    for (var idx = 0; idx < keys.length; idx++) {
        // find the desired key here
        if (keys[idx] == 'EmployerDetails') {
            var empDetails = empData[keys[idx]]
            empno = empDetails.EmpNo;
        }
    }
}


//var empno = JSON.parse(localStorage.getItem(localStorage.key(0))).EmployerDetails.EmpNo;
var pvarrData = new Array();
pvarrData[0] = empno;
pvarrData[1] = JSON.stringify($localStorage.message);
pvarrData[2] = $scope.SearchName;

TalentPoolService.insertSaveSearch(pvarrData).then(function successCallback(response) {

    if (response.data.status == true) {
        TalentPoolService.sucessNotify("Saved Search have been created successfully.", 5000, 640);

        $scope.SchoolSavedSearches(39424, 2, true).then(function successCallback(response) {
            console.log($scope.savedSearchList);
        });
    }
    else
        TalentPoolService.errorNotify("Saved Search could not be created.", 5000, 640);


}, function errorCallback(response) {
    TalentPoolService.errorNotify("Saved Search could not be created.", 5000, 640);
});

$("#addsavesearch_popup").modal("hide");
$scope.selected = [];
angular.forEach($scope.Candidatelist, function (val) {
    val.selected = false;
});
}

其他功能:

$scope.SchoolSavedSearches = function (id, saveSearchType, excludeDeActive) {

var pvarrData = new Array();
pvarrData[0] = id;
pvarrData[1] = saveSearchType;
pvarrData[2] = excludeDeActive;

TalentPoolService.GetSchoolSavedSearches(id, saveSearchType, excludeDeActive).then(function successCallback(response) {
    $scope.savedSearchList = response.data;

}, function errorCallback(response) {
    TalentPoolService.errorNotify("Saved Search could not be loaded.", 5000, 640);
});
}

0 个答案:

没有答案