'use strict';

(function() {

    var selectors = document.querySelectorAll('[data-role=linkage-selector]');

    var setOptions = function(select, data) {
        select.innerHTML = '';
        for (var i = 0, length = data.length; i < length; i++) {

            var option = document.createElement('option');
            option.value = data[i].value;
            option.innerHTML = data[i].label;

            select.appendChild(option);
        }
    };

    var getData = function(dimension, indexes, data) {
        var tempData = data;
        for (var i = 0; i < dimension - 1; i++) {
            tempData = tempData[indexes[i]].data;
        }
        return tempData;
    };


    for (var i = 0, length = selectors.length; i < length; i++) {

        var selector = selectors[i];
        var selectNames = selector.dataset.select.split(" ");

        selector.selects = selectNames.map(function(name) {
            return selectors[i].querySelector('[name=' + name + ']');
        });

        selector.selectIndexes = [];
        for (var j = 0, length = selector.selects.length; j < length; j++) {
              selector.selectIndexes[j] = 0;
        };

        var xhr = new XMLHttpRequest();
        xhr.open('GET', selector.dataset.src, false);
        xhr.send();

        var data = JSON.parse(xhr.responseText).data;
        var tempDataForInit = data;

        var _onchange = function(selector, index) {
            return function() {
                var thisData = getData(index + 1, selector.selectIndexes, data);
                selector.selectIndexes[index] = thisData.indexOf(selector.selects[index].value);

                var nextData = getData(index + 2, selector.selectIndexes, data);
                setOptions(selector.selects[index + 1], nextData);

            };
        };

        for (var j = 0, length = selector.selects.length; j < length; j++) {

              setOptions(selector.selects[j], tempDataForInit);
              tempDataForInit = tempDataForInit[0].data;

              if (j !== length - 1) {
                  selector.selects[j].onchange = _onchange(selector, j);
              }
        };


    }

}());
@@ -1165,214 +1165,8 @@
 %7D;%0A%0A
-        var xhr = new XMLHttpRequest();%0A        xhr.open('GET', selector.dataset.src, false);%0A        xhr.send();%0A%0A        var data = JSON.parse(xhr.responseText).data;%0A        var tempDataForInit = data;%0A%0A
     
@@ -1209,16 +1209,22 @@
 r, index
+, data
 ) %7B%0A    
@@ -1339,32 +1339,122 @@
 %0A               
+ for (var i = 0; i %3C thisData.length; i++) %7B%0A                    if (thisData%5Bi%5D.value ===
  selector.select
@@ -1457,22 +1457,16 @@
 lect
-Indexe
 s%5Bindex%5D
  = t
@@ -1465,28 +1465,42 @@
 dex%5D
- = thisData.indexOf(
+.value) %7B%0A                        
 sele
@@ -1506,32 +1506,38 @@
 ector.select
+Indexe
 s%5Bindex%5D
 .value);%0A%0A  
@@ -1528,16 +1528,84 @@
 dex%5D
-.value);
+ = i;%0A                        break;%0A                    %7D%0A                %7D
 %0A%0A  
@@ -1770,32 +1770,337 @@
  %7D;%0A        %7D;%0A%0A
+        var xhr = new XMLHttpRequest();%0A%0A        var _callback = function(selector) %7B%0A            return function() %7B%0A                if (xhr.readyState==4 && xhr.status==200) %7B%0A                    var data = JSON.parse(xhr.responseText).data;%0A                    var tempDataForInit = data;%0A%0A            
         for (var
@@ -2167,32 +2167,44 @@
 %0A%0A              
+            
 setOptions(selec
@@ -2243,32 +2243,44 @@
 ;%0A              
+    
+        
 tempDataForInit 
@@ -2317,24 +2317,36 @@
             
+        
+    
 if (j !== le
@@ -2353,24 +2353,36 @@
 ngth - 1) %7B%0A
+            
             
@@ -2443,38 +2443,239 @@
 r, j
-);%0A              %7D%0A        %7D;%0A
+, data);%0A                          %7D%0A                    %7D;%0A                %7D%0A            %7D;%0A        %7D;%0A%0A        xhr.onreadystatechange = _callback(selector);%0A        xhr.open('GET', selector.dataset.src, true);%0A        xhr.send();
 %0A%0A  

完成联动菜单功能，并将每个菜单请求数据改为异步执行。