HTML 파일에서 템플릿을 읽고 해당 모델의 값을 템플릿에 삽입하는 backbone.js보기가 있습니다. 이 값 중 하나는 변수 title
에 있으며 페이지의 요소 흐름을 방해 할 정도로 길 수 있습니다. 자바 스크립트를 사용하여 최대 값을 제한하고 싶습니다. 문자 수는 title
일 수 있으며, 결국 title
전체가 표시되어야하므로 백엔드에서 수행 할 수 있습니다.보기의 문자 수 제한 (Backbone.js)
템플릿을 렌더링 한 후에 title
이 포함 된 div를 선택하려고했지만 선택하지 못했습니다. 그렇지 않으면 어떻게해야합니까?
템플릿
<script type="text/template" id="tpl_PhotoListItemView">
<div class="photo_stats_title"><%= title %></div>
</script>
보기
PhotoListItemView = Backbone.View.extend({
tagNAme: 'div',
className: 'photo_box',
template: _.template($('#tpl_PhotoListItemView').html()),
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
console.log($(this.el).children('.photo_stats_title')); <!-- returns nothing -->
this.limitChars();
return this;
},
limitChars: function() {
var shortTitle = $(this.el).children('.photo_stats_title').html().substring(0, 10);
$(this.el .photo_stats_title).html(shortTitle);
}
});