gpt4 book ai didi

backbone.js - Backbone 事件和 Twitter Bootstrap 弹出窗口

转载 作者:行者123 更新时间:2023-12-03 14:26:31 25 4
gpt4 key购买 nike

在 twitter bootstrap popover 中插入主干渲染 View ,如下所示。问题是当插入该 View 的内容选项主干事件时不会触发。我在 div 中插入 View 以进行测试,使用 $(selector).html admissionShow.render().el 事件可以正常工作。先感谢您

      attendance = new Attendance()
attendance.url = "#{attendanceUrl}/#{attendanceId}"
attendance.fetch
success: ->
attendanceShow = new ExamAttendanceShow({model: attendance })
currentTarget.popover
html : true
content: ->
attendanceShow.render().el

此致,
乔治.

最佳答案

据我了解,根据您的代码和您的描述,您只是创建了弹出框的一个实例,但从未显示它。我有一个现场演示,但没有使用 CoffeeScript(我个人讨厌 CoffeeScript),你可以在 this jsfiddle 看到下面的代码.

数据1.json

{"content": "lorem ipsum dolor sit amet"}

索引.html
<div class="container">
<div class="row">
<button class="btn" data-target="popover">Popover</button>
</div>
<div class="row">&nbsp;</div>
<div class="row">
<button class="btn" data-action="change-content">Change Content</button>
</div>
</div>

main.js
var Main = Backbone.View.extend({
model: null,
item: null,
popover: false,

events: {
'click .btn[data-target]': 'button_click',
'click .btn[data-action="change-content"]': 'change_content'
},

initialize: function() {
_.bindAll(this);

this.model = new PopoverModel();
this.model.view = new PopoverContentView({model: this.model});

this.item = this.$('.btn[data-target]');
this.item.popover({
html: true,
content: this.model.view.render().el
});
},

button_click: function(event) {
if (!this.popover) {
this.model.url = 'js/data1.json';
this.model.fetch({
success: this.model_fetched
});
} else {
this.popover = false;
}
},

model_fetched: function() {
if (!this.popover) {
this.item.popover('show');
} else {
this.item.popover('hide');
}

this.popover = !this.popover;
},

change_content: function(event) {
this.model.set('content', 'Some random content... ' + parseInt(Math.random() * 10));
}
});

var PopoverModel = Backbone.Model.extend({
defaults: {
content: ''
}
});

var PopoverContentView = Backbone.View.extend({
initialize: function() {
_.bindAll(this);
this.listenTo(this.model, 'change', this.render);
},

render: function() {
this.$el.html(_.template('<%= content %>', this.model.toJSON()));
return this;
}
});


var main = new Main({
el: '.container'
});

关于backbone.js - Backbone 事件和 Twitter Bootstrap 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13627230/

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