2 템플릿 : 하나는 양식 용이고 다른 하나는 행 결과입니다. 이것이 나의 견해입니다. 양식이 표시되고 있지만 행이있는 경우이 행의 정적 템플릿 만 가져오고 <% = key %>
이 작동하지 않으며 양식이 사라진다는 의미입니다.jQuery.load를 사용하여 다른 템플릿에 템플릿 표시
APP.FromFront = Backbone.View.extend({
el: $("#content"),
events: {
"click #addLink" : "addLink",
"click .deleteLink" : "deleteLink"
},
template: _.template($('#content').html()),
initialize: function() {
this.bookmarks = new APP.BookmarksCollection();
this.render();
},
render: function() {
this.$el.html(this.$el.load("../../templates/form_template.html"));
this.bookmarks.each(function(bookmark) {
var bookJSON = bookmark.toJSON();
**//############ this is where it's doesn't work**
var temp=_.template(this.$el.load("../../templates/links_template.html"));
$("#links").append(temp(bookJSON));
},this);
},
})
왜 사용되지 않은 'template : _.template ($ ('content ') .html())가 있습니까? 왜 외부 파일을 사용하지 않고로드하려고합니까? ['load'] (http://api.jquery.com/load/)가 어떻게 작동하는지 이해합니까? 'this. $ el.html (this. $ el.load (url)) '과 같은 코드로 판단 할 때 나는 그렇게 생각하지 않는다. 우리 코드가 동일한 템플릿을 반복해서 가져 오려고한다는 것을 알고 있습니까? 브라우저가이를 캐시 할 수도 있지만 좋은 방법은 아닙니다. ['load'] (http://api.jquery.com/load/)는 비동기식입니다. 먼저 설명서를 읽으십시오. –
답변 해 주셔서 감사합니다. 내 템플릿이 index.html 페이지에있을 때 템플릿 "템플릿"에 사용되었습니다. 이 코드에서는 사용되지 않습니다. 정말로드하고 싶지는 않지만 사용하고 싶습니다. 그것이 index.html에 있지만 다른 파일에는없는 경우 어떻게하는지 알 것입니다. – BoltMaud