jquery 循环插件:寻呼机不工作
我在我的 web 应用程序中使用 jquery 循环插件和backbone.js。我正在我的 Backbone 视图之一中启动寻呼机。这是我现在的做法...
var SlideView = Backbone.View.extend({
template: _.template($('#SlideViewTemplate').html()),
initialize: function() {
_.bindAll(this, 'render');
this.render();
},
render: function() {
return $(this.el).html(this.template(this.model.toJSON()));
}
});
var SlideListView = Backbone.View.extend({
el: $('#SlideNavi'),
initialize: function() {
_.bindAll(this, 'render', 'populate');
this.render();
},
render: function() {
_(this.collection.models).each(function(item) {
this.populate(item);
}, this);
$('#Slideshow').cycle({
fx: 'fade',
pager: '#SlideNavi'
});
},
populateChildren: function(slide) {
var itemView = new SlideView({
model: slide
});
$(this.el).append(itemView.render());
}
});
new SlideListView({collection: someCollection});
这是我的视图模板,没什么奇特的:
<script type="text/template" id="SlideViewTemplate">
<%= name %>
</script>
这是填充后视图的外观:
<div class="SlideNavi">
<div>Service1</div>
<div>Service2</div>
<div>Service3</div>
<div>Service4</div>
</div>
现在,在 SlideListView
中使用的 el
是页面加载时为空。但是在填充视图后,我调用 jquery 循环插件来开始幻灯片放映。问题是幻灯片可以正常工作,但寻呼机却不能。没有 activeClass
被添加到分页器元素,如本演示中....
我在这里错过了什么?
I'm using the jquery cycle plugin and backbone.js in my webapp. I'm initiating the pager in one of my Backbone views. Here's how I'm doing it right now...
var SlideView = Backbone.View.extend({
template: _.template($('#SlideViewTemplate').html()),
initialize: function() {
_.bindAll(this, 'render');
this.render();
},
render: function() {
return $(this.el).html(this.template(this.model.toJSON()));
}
});
var SlideListView = Backbone.View.extend({
el: $('#SlideNavi'),
initialize: function() {
_.bindAll(this, 'render', 'populate');
this.render();
},
render: function() {
_(this.collection.models).each(function(item) {
this.populate(item);
}, this);
$('#Slideshow').cycle({
fx: 'fade',
pager: '#SlideNavi'
});
},
populateChildren: function(slide) {
var itemView = new SlideView({
model: slide
});
$(this.el).append(itemView.render());
}
});
new SlideListView({collection: someCollection});
Here's my view template, nothing fancy:
<script type="text/template" id="SlideViewTemplate">
<%= name %>
</script>
Here's how the view looks after being populated:
<div class="SlideNavi">
<div>Service1</div>
<div>Service2</div>
<div>Service3</div>
<div>Service4</div>
</div>
Now, el
used in SlideListView
is empty when the page is loaded. But after the view has been populated I call upon the jquery cycle plugin to start the slideshow. The thing is that slideshow is working, but the pager is not. No activeClass
is being added to pager elements as shown in this demo....
What am I missing over here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在此处找到了答案。确保包含
jquery.cycle.all.js
,而不是jquery.cycle.lite.js
。I found the answer over here. Make sure to include
jquery.cycle.all.js
, notjquery.cycle.lite.js
.