2 回答
TA贡献1776条经验 获得超12个赞
您可以filter在dResponse阵列上使用该功能。您没有指定您想要的过滤器,但这是一个基本示例。
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
function getIncidents(){
$.ajax({
url: "https://office4.bt.com/sites/ccim/Mobile/_api/web/lists/getbytitle('Incident List')/items?$select=Title,Id,Priority,IncidentStart,IncidentStatus,IncidentTitle,UpdateResolution,ImpactedArea",
type: "GET",
headers: {"accept": "application/json;odata=verbose"},
success: function (data) {
var dResponse = data.d.results;
// we filter the data before using it.
// we use const because we do not plan on reassigning the variable.
const filteredResponse = dResponse.filter((item) => item.someFilteringData);
var results = document.getElementById('Results');
results.innerHTML += "<tr><td>Incident<br>Reference</td><td style='width:20px'></td><td>Priority</td><td style='width:20px;'></td><td>Start Time</td><td style='width:20px'></td><td style='width:170px'>Issue</td><td style='width:20px'></td><td style='width:170px'>Latest Update</td><td style='width:20px'></td></tr>";
for(var obj in filteredResponse){
results.innerHTML += "<tr style='font-size:10pt'><td>"+filteredResponse [obj].Title+"</td><td></td><td>"+dResponse[obj].Priority+"</td><td></td><td>"+dResponse[obj].IncidentStart+"</td><td></td><td>"+filteredResponse [obj].IncidentTitle+"</td><td></td><td>"+dResponse[obj].UpdateResolution+"</td></tr>";
}
}
});
}
</script>
TA贡献1783条经验 获得超4个赞
那么最后你想通过一个或多个对象属性过滤一组对象吗?是的,这很容易。
let myArray = [ {a: 10, b: 'red'}, {a: 20, b: 'green'} ]
let filteredArray = myArray.filter(x=>x.b=='green')
一种更优雅的方式(如果可能)是将参数发送到您的 API 并过滤服务器端。
添加回答
举报