2014-05-22 2 views
0

현재 구문 분석 데이터베이스에 저장된 결과라는 개체 배열이 있습니다. 결과 배열에있는 각 객체의 속성에 액세스하려고했습니다.배열 내의 개체 속성에 액세스 할 수 없습니다.

결과 배열의 각 요소를 통과하는 for 루프와 그 내부에있는 for 루프를 통해 각 개체에서 특정 속성을 검색하고 검색합니다. 이 경우 속성은 maxPrice이며 데이터베이스에 저장된 정수를 검색하려고합니다. 이 For 루프를 실행하면 찾고있는 번호 대신 맨 아래에 표시되는 것과 같이 긴 목록이 반환됩니다.

for (var i = 0; i < results.length; i++)  
{ 
    var stuff; 
    var object = results[i]; 
    for (var maxPrice in object) //max price is the property 
    { 
      stuff = object[maxPrice]; 
      console.log(maxPrice, stuff); 
     } 
    } 

로그 : results 객체의 배열처럼

I2014-05-22T20:36:17.589Z] _serverData 
I2014-05-22T20:36:17.589Z] _opSetQueue 
I2014-05-22T20:36:17.589Z] attributes 
I2014-05-22T20:36:17.589Z] _hashedJSON 
I2014-05-22T20:36:17.589Z] _escapedAttributes 
I2014-05-22T20:36:17.589Z] cid 
I2014-05-22T20:36:17.589Z] changed 
I2014-05-22T20:36:17.589Z] _silent 
I2014-05-22T20:36:17.589Z] _pending 
I2014-05-22T20:36:17.589Z] _hasData 
I2014-05-22T20:36:17.589Z] _previousAttributes 
I2014-05-22T20:36:17.589Z] id 
I2014-05-22T20:36:17.589Z] createdAt 
I2014-05-22T20:36:17.589Z] updatedAt 
I2014-05-22T20:36:17.589Z] className 
I2014-05-22T20:36:17.589Z] constructor 
I2014-05-22T20:36:17.589Z] on 
I2014-05-22T20:36:17.589Z] off 
I2014-05-22T20:36:17.589Z] trigger 
I2014-05-22T20:36:17.589Z] bind 
I2014-05-22T20:36:17.589Z] unbind 
I2014-05-22T20:36:17.589Z] _existed 
I2014-05-22T20:36:17.589Z] initialize 
I2014-05-22T20:36:17.589Z] toJSON 
I2014-05-22T20:36:17.589Z] _toFullJSON 
I2014-05-22T20:36:17.589Z] _refreshCache 
I2014-05-22T20:36:17.589Z] dirty 
I2014-05-22T20:36:17.589Z] dirtyKeys 
I2014-05-22T20:36:17.589Z] _toPointer 
I2014-05-22T20:36:17.589Z] get 
I2014-05-22T20:36:17.589Z] relation 
I2014-05-22T20:36:17.589Z] escape 
I2014-05-22T20:36:17.589Z] has 
I2014-05-22T20:36:17.589Z] _mergeMagicFields 
I2014-05-22T20:36:17.589Z] _copyServerData 
I2014-05-22T20:36:17.589Z] _mergeFromObject 
I2014-05-22T20:36:17.589Z] _startSave 
I2014-05-22T20:36:17.590Z] _cancelSave 
I2014-05-22T20:36:17.590Z] _finishSave 
I2014-05-22T20:36:17.590Z] _finishFetch 
I2014-05-22T20:36:17.590Z] _applyOpSet 
I2014-05-22T20:36:17.590Z] _resetCacheForKey 
I2014-05-22T20:36:17.590Z] _rebuildEstimatedDataForKey 
I2014-05-22T20:36:17.590Z] _rebuildAllEstimatedData 
I2014-05-22T20:36:17.590Z] set 
I2014-05-22T20:36:17.590Z] unset 
I2014-05-22T20:36:17.590Z] increment 
I2014-05-22T20:36:17.590Z] add 
I2014-05-22T20:36:17.590Z] addUnique 
I2014-05-22T20:36:17.590Z] remove 
I2014-05-22T20:36:17.590Z] op 
I2014-05-22T20:36:17.590Z] clear 
I2014-05-22T20:36:17.590Z] _getSaveJSON 
I2014-05-22T20:36:17.590Z] _canBeSerialized 
I2014-05-22T20:36:17.590Z] fetch 
I2014-05-22T20:36:17.590Z] save 
I2014-05-22T20:36:17.590Z] destroy 
I2014-05-22T20:36:17.590Z] parse 
I2014-05-22T20:36:17.590Z] clone 
I2014-05-22T20:36:17.590Z] isNew 
I2014-05-22T20:36:17.590Z] change 
I2014-05-22T20:36:17.590Z] existed 
I2014-05-22T20:36:17.590Z] hasChanged 
I2014-05-22T20:36:17.590Z] changedAttributes 
I2014-05-22T20:36:17.590Z] previous 
I2014-05-22T20:36:17.590Z] previousAttributes 
I2014-05-22T20:36:17.590Z] isValid 
I2014-05-22T20:36:17.590Z] validate 
I2014-05-22T20:36:17.590Z] _validate 
I2014-05-22T20:36:17.590Z] getACL 
I2014-05-22T20:36:17.590Z] setACL 
+0

하나의 속성 만 가져 오기 위해 'for-in' 문이 필요하지 않습니다. 그냥'object.maxPrice'를 사용하십시오 –

+1

... 오, 당신은 재산의 이름을 모르십니까? 데이터 구조가 어떻게 보이는지 보여줘야합니다. –

답변

1

이 보이지만, 그 객체는 당신이 기대하고있는 유형 (구문 분석에서 아마도 내부 구조)이 아니다. 반환 된 객체의 값에 액세스 할 수

results[i].get("fieldName") 

: 구문 분석 문서 얼핏에서, 내 생각 엔 당신이 뭔가를 할 필요가있다. 즉, 미리 액세스하려는 필드 이름을 알아야합니다.

0

또는 구문 분석 객체에서 toJSON() 메서드를 사용하여 데이터의 json 객체를 검색 할 수도 있습니다.

results[i].toJSON(); 
관련 문제