나는이 문제를 해결하는 방법을 알아 내는데 어려움을 겪고 있습니다.데이터 루핑
결국 드롭 다운을 동적으로 만들려고합니다. 나는 현재이 작업을하고 있지만 불필요한 4 개의 아약스 호출 (각 카테고리 당 1 개의 자식을 가져 오기 위해)을 만들고 있습니다.
열 : ID, 이름, 위치, 카테고리
행 샘플 데이터 :
1, 파란색, 룸, 색
2, 빨강, 차고
내 데이터베이스 구조는 매우 비슷 색상
3, 공, 마당, 장난감
4, 트럭, 상자, 장난감
5, 인형, 방, 장난감
내가하려는 것은 먼저 내 테이블의 모든 범주를 찾아 고유 한 가치를 얻는 것입니다. 색상이 두 번 나열되어 있고 장난감이 3 번 나열되지 않으려 고합니다. 색상은 1 개, 장난감은 1 개로 모두 고유합니다.
다음으로 나는 모든 것을 다시 반복해야하고 다음은 각 카테고리 아래에있는 모든 이름입니다.
<root>
<dataPoints>
<id>1</id>
<name>Blue</name>
<location>Room</location>
<category>Color</category>
</dataPoints>
<dataPoints>
<id>2</id>
<name>Red</name>
<location>Garage</location>
<category>Color</category>
</dataPoints>
<dataPoints>
<id>3</id>
<name>Ball</name>
<location>Yard</location>
<category>Toy</category>
</dataPoints>
<dataPoints>
<id>4</id>
<name>Truck</name>
<location>Box</location>
<category>Toy</category>
</dataPoints>
<dataPoints>
<id>5</id>
<name>Doll</name>
<location>Room</location>
<category>Toy</category>
</dataPoints>
</root>
가 거기인가 : 레드
색상 = 블루,
장난감 = 공, 트럭, 인형
function makeDataPointsTest() {
$.ajax({
url: "../db_api.php",
type: 'GET',
dataType: 'xml',
cache: false,
data: {
sp: "Watson_DataPointsList",
type: "xml",
params: {
category: ''
}
},
error: function(err) {
alert(err.statusText);
},
success: function(data) { //This is the data I am getting back from the database.
// It is returned as an XML object.
var dataTmp = []; //temporary array
var dataCats; //var to hold the unique categories
$(data).find('dataPoints').each(function(i) { //Node of XML is called DataPoints.
var tmp = $(this).find('category').text(); //In each Node (row) find the category name
dataTmp.push(tmp); //Push that category name to an array
});
dataCats = _.uniq(dataTmp); //using underscore.js I now have each unique category in //the database
//Here is where I am stuck
//I now need to loop through each node again and create an array that contains each of //the names under each of the categories.
}
});
}
결과 구조 (데이터) : 같은
결과가 보일 것이다 이 시점에서이 jquery를 수행하는 간단한 방법은 무엇입니까?
이
내가 만들려고하고있는 무슨 동적으로 이미지: http://i.stack.imgur.com/3Emec.png
값을 함께 페어링 할 수 있습니까? 나는 기본적으로 여러 개의 드롭 다운 메뉴를 작성하고 있습니다.각 범주는 자체 메뉴이며 해당 범주에 연결된 각 레코드가 옵션입니다. 그래서 내가 이런 식으로 구축해야합니다 ' <선택 이름 = "독특한 카테고리 1"> <옵션 ID = "+ ROW ID를 +"이름 = "+ 카테고리 +"> + 이름 + <옵션 ID = "+ 행 ID +"이름 = "+ 카테고리 +"> + 이름 + <선택 이름 = "고유의 카테고리 2"> <옵션 ID = "+ 행 ID +"이름 = "+ 카테고리 +"> + NAME + <옵션 ID = "+ 행 ID +"이름 = "+ 카테고리 +"> + 이름 + 내가 필요로하는 경우 행의 COLS 모두에 액세스 할 수있을 것입니다 방법 ' – SBB