2017-10-11 8 views
0

4 개의 선택 항목이 있으며 각 선택 항목은 이전 선택 항목의 선택 사항을 기반으로합니다. 소스 항목에 대한 요청과 함께 동적 데이터를 보내려면 어떻게해야합니까?요청에 따라 데이터를 보내는 방법 X 편집 가능

나는 함수를 사용했지만 jQuery getJSON()이 비동기이며 필요한 방식으로 작동하지 않는다는 것을 알았습니다.

내가 현재 가지고있는 것입니다. 그리고 네, 저도 잘 작동하지 않습니다.

// Location_Site X-editable init 
$("#location-aisle").editable({ 
    url: BASE_URL + "item/edit_item", 
    title: "Site aisle", 
    params: { 
     type: "location-site" 
    }, 
    sourceCache: false, 
    source: BASE_URL + "item/get_aisles", 
    sourceOptions: { 
     headers: { 
      "aisle-id": $("#location-site").val() 
     } 
    } 
}); 

답변

0

성공 이벤트를 사용하고 원본 매개 변수를 수동으로 설정하는 것으로 나타났습니다. 이 코드는 확인하고 유효하지 않은 응답이나 유효하지 않은 변수 귀중품 취급하지 않습니다

// Location_Site X-editable init 
$("#location-site").editable({ 
    url: BASE_URL + "item/edit_item", 
    title: "Location site", 
    params: { 
     type: "location-site" 
    }, 
    source: sites, 
    success: function (response, newValue) { 
     // Get aisles for site 
     $.getJSON(BASE_URL + "item/get_aisles/" + newValue, function(data) { 
      outputDebug(data); 

      // Load aisles into drop down 
      if (data && data.length > 0) { 
       $("#location-aisle").editable("option", "source", data); 
       $("#location-aisle").editable("enable"); 
      } else { 
       window.alert("Failed to load aisles for selected site."); 
      } 
     }, "json"); 
    } 
}); 

여기에 다음 단계가 다른 사람에게 더 나은 예를

// Location_Site X-editable init 
$("#location-aisle").editable({ 
    url: BASE_URL + "item/edit_item", 
    title: "Site aisle", 
    params: { 
     type: "location-aisle" 
    }, 
    success: function (response, newValue) { 
     // Get columns for site 
     $.getJSON(BASE_URL + "item/get_columns/" + newValue, function(data) { 
      outputDebug(data); 

      // Load aisles into drop down 
      if (data && data.length > 0) { 
       $("#location-column").editable("option", "source", data); 
       $("#location-column").editable("enable"); 
      } else { 
       window.alert("Failed to load columns for selected site."); 
      } 
     }, "json"); 
     // 
     // Get rows for site 
     $.getJSON(BASE_URL + "item/get_rows/" + newValue, function(data) { 
      outputDebug(data); 

      // Load aisles into drop down 
      if (data && data.length > 0) { 
       $("#location-row").editable("option", "source", data); 
       $("#location-row").editable("enable"); 
      } else { 
       window.alert("Failed to load rows for selected site."); 
      } 
     }, "json"); 
    } 
}); 

참고를 제공하는 드롭 다운입니다.