내가 가지고있는 많은 데이터 모델에 하나를 다음 지역은 고객이, 클라이언트는 노트를 가지고 및 경고JQuery와 중첩 아약스 목록과 온 클릭 기능 디자인
을 다음과 같이 나는 가져 오는 동안 채우기를 구현 한 :
다음과 같이When the page loads all the regions load and populate their view.
When you click on a region all the clients for that region load and populate their view.
When you click on a client all the notes/alerts for that client load and populate .their view.
이의 jQuery 코드는 같습니다
RegionDAO.getRegions(function(data){
$("#regionlist").empty();
$("#clientlist").empty();
$(data).each(function(index){
$("#regionlist").append("<li class='regionrow blendRow' id='"+this.rid+"'>" + this.name + "</li>");
});
$('.regionrow').blend(150);
$(".regionrow").click(function(){
$(".regionrow").removeClass("activerow");
$("#"+$(this).attr("id")).addClass("activerow");
RegionDAO.getClientsByRegion($(this).attr("id"),function(data){
$("#clientlist").empty();
$(data).each(function(index){
$("#clientlist").append("<li class='clientrow blendRow' id='"+this.cid+"'>" + this.lastname + "</li>");
});
$('.clientrow').blend(150);
$('.clientrow').click(function(){
RegionDAO.getNotesByClient($(this).attr("id"),function(data){
$("#notelist").empty();
$(data).each(function(index){
$("#notelist").append("<li class='noterow blendRow' id='"+this.nid+"'>" + this.text + "</li>");
});
$('.noterow').blend(150);
});
RegionDAO.getAlertsByClient($(this).attr("id"),function(data){
$("#alertlist").empty();
$(data).each(function(index){
$("#alertlist").append("<li class='alertrow blendRow' id='"+this.nid+"'>" + this.text + "</li>");
});
$('.alertrow').blend(150);
});
});
});
});
});
});
모든 것이 정말 잘 내가 implemen 때까지 작동 별도의 클릭 핸들러에서 addRegion 기능. 내가 원하는 것은 save (나는 그것을위한 핸들러가있다)를 클릭하면 regions리스트가 다시 채워진다. 문제는 그것이 seprate 핸들러에 있기 때문에 전체 중첩 목록을 다시 정의해야합니다.> 함수 구조를 다시 클릭하고 코드 중복을 다시 정의해야합니다.
$("#addregiondialog").dialog({
title: 'Add a region',
show: "up",
open: function(event, ui){
},
buttons: { "Save": function() {
$(this).dialog("close");
RegionDAO.addRegion($('#region_name').val());
RegionDAO.getRegions(function(data){
$("#regionlist").empty();
$("#clientlist").empty();
$(data).each(function(index){
$("#regionlist").append("<li class='regionrow blendRow' id='"+this.rid+"'>" + this.name + "</li>");
});
$('.regionrow').blend(150);
$(".regionrow").click(function(){
//MUST REDEFINE THE CLIENT LOADING AND CLICK STRUCTURE
//HERE AS WELL AS THE CLICKS AND EVERYTHING FOR NOTES AND ALERTS. IE THE ABOVE CODE>
});
});
}
}
});
이 나에게 매우 일반적인 패턴처럼 보인다 가장 좋은 방법은 분명하기 때문이다 구현하기 위해 무엇인지 궁금 해서요 (작동하지만,)이 좋지 않은 : 여기에 addRegion 코드를 다음과 같습니다.
입니다 (http://api.jquery.com/on/)에서 위임 된 이벤트를 찾으십시오. – dezso
이해가 안됩니다. 의견을 설명해주십시오. – n4rzul