나는 query
을 수행하고 이후에 results
을 필터링하는 구문 분석 코드 기능을 작업 중입니다. 이 코드는 JavaScript로 작성된 첫 번째 코드 줄이므로 다음 문제를 해결하는 방법을 찾을 수 없습니다.구문 분석 코드에서 개체를 가져 오는 방법
문제는 내 필터 조건자가 someArray
변수에 저장된 일부 요소를 필요로한다는 것입니다. someArray
의 모든 요소는 아직 가져 오지 않습니다. 그러나 Parse.Object를 가져 오는 것은 비동기 호출이므로 true
또는 false
이 filter()
에 의해 반환 될 가능성이 없습니다.
이 문제를 어떻게 해결할 수 있습니까?
아니면 내가 알고 있지만
arrayElement with name:objectundefiend
는 arrayElment
로 표현하는 객체 인 name
칼 럼이있는 arrayElement
console.log("arrayElement with name: ".concat(typeof(arrayElement), arrayElement.get("name")));
인쇄를 가져 오지 않을 때, 사실을 잘못 해석하고 항상 정의 되나요?
//The cloud code
Parse.Cloud.define("search", function(request, response) {
var query = new Parse.Query("Location");
query.withinKilometers("gps", request.params.searchLocation, request.params.searchRadius/1000);
query.find({
success: function(results) {
// results is an array of Parse.Object.
var locations = results.filter(function(location) {
console.log("Location with name: ".concat(location.get("name")));
var someArray = location.get("someArray");
if (someArray instanceof Array) {
console.log("The array of this location has ".concat(someArray.length, " elements."));
someArray.forEach(function(arrayElement) {
arrayElement.fetch().then(
function(fetchedArrayElement) {
// the object was fetched successfully.
console.log("arrayElement with name: ".concat(typeof(fetchedArrayElement), fetchedArrayElement.get("name")));
if (menuItem) {};
return true;
},
function(error) {
// the fetch failed.
console.log("fetch failed");
});
});
}
});
response.success(locations);
},
error: function(error) {
// error is an instance of Parse.Error.
response.error(error);
}
});
});
몇 가지 유용한 링크 :이 권리를 읽고 있어요 경우
유용 들리지만, 문제는 (내가 질문에 그것을 간체), 즉의 요소' someArray'는 다른 Parse Objects의 배열 열을 가진 Parse Objects입니다. 어떻게 그들을 포함시킬 수 있습니까? '응답 '을 가능한 한 작게 만들기 위해 어떻게 가져온 것들을 모두 "제거"할 수 있습니까? '필터 '는 뭐가 잘못 됐어? –
도트 표기법을 사용합니다. 즉, query.include ('someArray.someOtherColumn'); .filter에 관해서는 내부에서 비동기 작업을 수행하지 않는 한 괜찮습니다. – Fosco
완벽하게 작동합니다! 고마워요! –