次の HTML テンプレートがあります。
<li id="imovel" style="<%= display %>">
<div class="thumbnail">
<a href="#">
<img src="http://placehold.it/90x60"></img>
<%= textvar %>
</a>
</div>
</li>
表示はdisplay: none
物display: block
によっては1/2です。
このビューが欲しいです:
var imovelView = Backbone.View.extend({
el: $('#imovel')
,template: _.template( $("#listing_template").html())
,events: {
"change:display #imovel" : "activate"
}
,initialize: function(){
this.on('change:display', this.toggle, this);
this.collection.bind('add', this.render, this);
}
,activate: function(item){
alert("change display");
}
,render: function(item){
var showPerPage = $('#show_per_page').val();
var totalEntries = this.collection.length;
var pageMax = Math.ceil( showPerPage/totalEntries );
var displayValue = "display: none;";
if(totalEntries <= showPerPage){
displayValue = "display: block;";
}
var variables = { textvar: item.get("Lat"), display: displayValue };
var template = this.template( variables );
$('#max_page').val(pageMax);
$('#content').append( template );
resizeViewport();
}
});
表示するときchange:display
は、el スタイルの表示プロパティの変更をリッスンすることを意味します。
それは可能ですか?