gpt4 book ai didi

javascript - 动态更改 Marionette ItemView 模板

转载 作者:搜寻专家 更新时间:2023-10-31 22:06:43 25 4
gpt4 key购买 nike

我在 Marionette 中有这个 ItemView:

App.View.MovieListItem = Marionette.ItemView.extend({
tagName: 'li',
className: 'movie',
model: App.Model.Movie,
id: function() {
return 'movie-'+this.model.get('imdb')
},

initialize: function () {
this.render();
},

template: _.template('<a href="javascript:;">'+
'<i class="fa fa-eye fa-3"></i>'+
'<span class="cover"></span>'+
'<strong><%= title %></strong>'+
'<small><%- year %></small>'+
'<small2>Cached</small2>'+
'</a>'),
});

我想知道是否可以动态创建模板?因为有时我想(基于检查某些东西的方法)删除 small2 标签。

最佳答案

Marionette has a function称为 getTemplate,可用于返回动态模板。

例子:

App.View.MovieListItem = Marionette.ItemView.extend({
tagName: 'li',
className: 'movie',
model: App.Model.Movie,
id: function() {
return 'movie-'+this.model.get('imdb')
},

initialize: function () {
this.render();
},

getTemplate: function(){
if(condition){
return _.template(/* HTML STRING */);
}else{
return _.template(/* ANOTHER HTML STRING */);
}
}
});

关于javascript - 动态更改 Marionette ItemView 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24228436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com