【问题标题】:Angular js select 2 change ajax urlAngular js 选择 2 更改 ajax url
【发布时间】:2015-02-20 06:40:20
【问题描述】:

我正在使用 Angularjs + select 2。我必须动态更改 Ajax URL 以获取基于过滤器的自动完成值

例子:

我有 3 个不同的 API URL,

Movie, 
Song,
Image  

如果用户选项是电影,那么请求应该转到电影 REST API。

我关注了这个网址:select2 change ajax url

并在 Angular js 中完成以下操作

$scope.getbaseURL = function () {
    $scope.baseurl = GENERAL_CONFIG.WebApi_Base_URL[$scope.type];
    return $scope.baseurl;
}

$scope.multi = {
    minimumInputLength: 5,
    ajax: {
        headers: {
            'Content-Type': 'application/json'
        },
        url: $scope.getbaseURL() + "Lookup?lookup=Lookupvalue",
        data: function (term, page) {
            return {
                key: term
            }; // query params go here
        },
        results: function (data, page) {
            return {
                results: data.LookupValue
            };
        }
    },
    dropdownCssClass: "bigdrop"
}

我的 $scope.type 是一个带有

的下拉菜单
image , 
Movie 
Song 

但它不会动态更改基本 URL 或基于类型选择。

GENERAL_CONFIG.WebApi_Base_URL[$scope.type] 是配置文件中 REST URL 的集合

谁能帮帮我,谢谢

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:

    url 的配置参数应该是一个函数,如果你希望它是动态的。试试这个:

    $scope.getbaseURL = function () {
        $scope.baseurl = GENERAL_CONFIG.WebApi_Base_URL[$scope.type];
        return $scope.baseurl + "Lookup?lookup=Lookupvalue";
    }
    
    $scope.multi = {
        minimumInputLength: 5,
        ajax: {
            headers: {
                'Content-Type': 'application/json'
            },
            url: $scope.getbaseURL,
            data: function (term, page) {
                return {
                    key: term
                };
            },
            results: function (data, page) {
                return {
                    results: data.LookupValue
                };
            }
        },
        dropdownCssClass: "bigdrop"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      • 2018-05-05
      • 2017-11-19
      • 1970-01-01
      • 2017-05-01
      • 2017-05-06
      相关资源
      最近更新 更多