gpt4 book ai didi

javascript - 如何过滤 GET 请求?

转载 作者:可可西里 更新时间:2023-11-01 17:25:14 24 4
gpt4 key购买 nike

我正在使用网络请求检索数据并将其显示在网页上。我不想使用 Angular 的 ng-if 并隐藏不符合条件的数据,而是根本不检索数据。

JS:

var app = angular.module('myApp', ['ngSanitize']);
app.controller('MainCtrl', function($scope, $http, $q){
$(document).ready(function() {
$scope.getAdminList();
});
$scope.prepContext = function(url,listname,query){
var path = url + "/_api/web/lists/getbytitle('" + listname + "')/items" + query;
console.log(path);
return path;
}
$scope.getAdminList = function() {
adminList = $http({
method: 'GET',
url: this.prepContext(siteOrigin+"/corporate/projecthub/anchormn/associates","User Administration","?$orderBy=LastName"),
headers: {
"Accept": "application/json; odata=verbose"
}
}).then(function(data) {
//$("#articleSection").fadeIn(2000);
console.log("adminlist", data.data.d.results);
$scope.users = data.data.d.results;
});
};
});

记录 data.data.d.results; 记录类似于以下内容的对象数组:

{
0: {
"ID": 21,
"Name": Me
},
1: {
"ID": 14,
"Name": Test
},
2: {
"ID": 3,
"Name": Test1
}
}

不使用 ng-if="user.ID == 21,我如何只使用网络请求检索项目?

最佳答案

根据您的请求 header 和 URI($orderBy),我了解到您的服务器是 OData 服务器。如果服务器正确实现过滤器,您可以使用一些 OData $filter 表达式作为查询字符串的一部分,类似于您的 $orderBy。

例子:

GET Products?$filter=ProductName+eq+%27iPhone%27

请检查网址:http://www.odata.org/documentation/odata-version-2-0/uri-conventions/

Logical Operators

Eq Equal /Suppliers?$filter=Address/City eq 'Redmond'
Ne Not equal /Suppliers?$filter=Address/City ne 'London'
Gt Greater than /Products?$filter=Price gt 20
Ge Greater than or equal /Products?$filter=Price ge 10
Lt Less than /Products?$filter=Price lt 20
Le Less than or equal /Products?$filter=Price le 100
And Logical and /Products?$filter=Price le 200 and Price gt 3.5
Or Logical or /Products?$filter=Price le 3.5 or Price gt 200
Not Logical negation /Products?$filter=not endswith(Description,'milk')

Arithmetic Operators
Add Addition /Products?$filter=Price add 5 gt 10
Sub Subtraction /Products?$filter=Price sub 5 gt 10
Mul Multiplication /Products?$filter=Price mul 2 gt 2000
Div Division /Products?$filter=Price div 2 gt 4
Mod Modulo /Products?$filter=Price mod 2 eq 0

Grouping Operators
( ) Precedence grouping /Products?$filter=(Price sub 5) gt 10

关于javascript - 如何过滤 GET 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48330592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com