所以我试图通过Javascript中的id
从下面的列表中检索一个集合。我怎样才能做到这一点?我最近一直在寻找方法,但我无法做到。
{'id':1,"firstTeam":"Barcelona","secondTeam":"Real Madrid","Time":"14:00","commentator":"Unknown","championship":"UEFA","channel":"BEIN SPORT","iframe":'<iframe width="560" height="315" src="https://www.youtube.com/embed/pQRO_5dtqrk" frameborder="0" allowfullscreen></iframe>'}
{'id':2,"firstTeam":"Barcelona","secondTeam":"Real Madrid","Time":"14:00","commentator":"Unknown","championship":"UEFA","channel":"BEIN SPORT","iframe":'<iframe width="560" height="315" src="https://www.youtube.com/embed/pQRO_5dtqrk" frameborder="0" allowfullscreen></iframe>'}
答案 0 :(得分:1)
var testArray = [{'id':1,"firstTeam":"Barcelona","secondTeam":"Real Madrid","Time":"14:00","commentator":"Unknown","championship":"UEFA","channel":"BEIN SPORT","iframe":'<iframe width="560" height="315" src="https://www.youtube.com/embed/pQRO_5dtqrk" frameborder="0" allowfullscreen></iframe>'},
{'id':2,"firstTeam":"Barcelona","secondTeam":"Real Madrid","Time":"14:00","commentator":"Unknown","championship":"UEFA","channel":"BEIN SPORT","iframe":''}];
var filtered = testArray.filter(filterFunction);
// Let's assume you want to filter by ID, stored in $scope variable.
$scope.filterById = 2;
function filterFunction(val) {
return value.id == $scope.filterById;
}
答案 1 :(得分:0)
是Find object by id in an array of JavaScript objects
的重复使用jQuery.grep:
// The following is being added to a list of type Foo
Foo(
varone = "stringvalue",
vartwo = "stringvalue",
varthree = true
)