이 코드를 고려하십시오 최초의 "이"참조를 유지 :중첩 jQuery의으로 .Append() .each(), 추가()와
var ul = $(".list_b").find("li").remove().end();
$.each(Sites, function (index, value) {
ul.append(
$("<li></li>")
.append(
$("<span></span>")
.addClass("img_b")
.css("background-image", "url(pin.png)")
.text(value.Name)
)
.append(
$("<div></div>")
.addClass("div_archives")
.each(value.Documents, function (index2, value2) {
this.append(
$("<a></a>")
.attr({ href: value.URL })
.attr({ target: "_blank" })
.html(value2.Name)
.append(
$("<img />")
.attr({ src: "../img/icon_" + value2.Type + ".png" })
.attr({ alt: "Archive " + value2.Tipo })
)
)
}
)
)
);
});
그리고 소스 객체로이 JSON을.
는[ {
"Id":1,
"Name":"Rachel Weiss",
"Color":"FF0000",
"Symbol":"A",
"Latitude":51.123123,
"Longitude":12.131231,
"Documents":[
{
"Id":1,
"Name":"Document 1",
"Ext":"pdf",
"Type":"pdf",
"URL":"http://www.google.com"
},
{
"Id":2,
"Name":"Document 2",
"Ext":"doc",
"Type":"word",
"URL":"http://www.yahoo.com"
},
{
"Id":3,
"Name":"Document 3",
"Ext":"xls",
"Type":"excel",
"URL":"http://www.amazon.com"
}
],
"Notes":[
{
"Id":0,
"Texto":"test test"
},
{
"Id":1,
"Texto":"test test. test test"
}
]},{
"Id":2,
"Name":"Natalie Portman",
"Color":"00FF00",
"Symbol":"B",
"Latitude":51.123123,
"Longitude":12.131231,
"Documents":[
{
"Id":11,
"Name":"Document 11",
"Ext":"doc",
"Type":"word",
"URL":"http://www.google.com"
}
],
"Notes":[
{
"Id":10,
"Texto":"test test. test test. test test."
}
]} ... ]
내가 달성하기 위해 노력 해요 목표는 부모 <div></div>
블록으로 <a></a>
블록을 추가하는 것입니다,하지만 난 외부 "이"개체를 참조 할 수있는 방법을 찾을 수 없습니다.
나는 이것이 절름발이 질문이어야 함을 알고 있지만 모든 아이디어가 매우 환영받을 수 있도록 단서가 없습니다.
미리 감사드립니다.
이 추가적으로 정보 : 어느 this
도 $(this)
작품, 두 가지 당신이 필요로 내부
jQuery가 최대한 익숙했습니다. – BoltClock
템플릿 엔진을 사용 해본 적이 있습니까? 나는 jQuery Templates를 추천합니다 : http://api.jquery.com/category/plugins/templates/ –
@BoltClock : Rachel Weiss와 Natalie Portman이 특징입니다! –