jQuery를 사용하여 객체 배열을 반복하고 특정 기준을 충족하는 객체를 반환하려면 어떻게해야합니까? 당신이 테스트하려는 조건이 엄격한 평등 이외 인 경우 즉, 사용자 정의 비교를 실행 반복jQuery : 특정 속성을 가진 개체를 찾는 방법이 특정 값과 일치합니까?
이var matches = jQuery.grep(array, function(item) {
// this is a reference to the element in the array
// you can do any test on it you want
// return true if you want it to be in the resulting matches array
// return false if you don't want it to be in the resulting matches array
// for example: to find objects with the Amount property set to a certain value
return(item.Amount === 100);
});
// matches contains all objects that matches
if (matches.length) {
// first match is in matches[0]
}
는, 당신은 배열의 어떤 종류를 사용해야합니다 :
이는 개체의 상태와 상태에 따라 다릅니다. 샘플 데이터가 필요합니다. –
무엇을하려고합니까? 코드를 게시 할 수 있습니까? – elclanrs
각 개체에는 ID 및 금액 속성이 있습니다. 배열은 12 개 정도의 객체를 포함합니다. – David