Dav*_*vid 0 javascript carousel twitter-bootstrap ember.js
试图理解为什么它不起作用.
我有类似的东西.
<div class="carousel slide" id="new-prospect-container">
<div class="carousel-inner">
{{#each model}}
<div class="item">
...
</div>
{{/each}}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
但是Botostrap的第一个类api意味着我们不需要执行任何JS方法,它们的小部件将自动运行.问题是我怀疑Bootstrap会在我的{{model}}被Ajax请求填满之前执行此操作.所以这个Carousel将不起作用.
令人讨厌的是我已经尝试关闭他们的数据-api - $(document).off('.data-api'); 并手动调用他们的轮播方法 - 仍然无法正常工作.
旋转木马使用硬编码数据 - 但是一旦我尝试从我的Ember模型填充旋转木马div项目,它就会停止工作.
1 - 我希望这个jsfiddle解决你的问题.
App.CarouselView = Ember.View.extend({
templateName: 'carousel',
classNames: ['carousel', 'slide'],
init: function() {
this._super.apply(this, arguments);
// disable the data api from boostrap
$(document).off('.data-api');
// at least one item must have the active class, so we set the first here, and the class will be added by class binding
var obj = this.get('content.firstObject');
Ember.set(obj, 'isActive', true);
},
previousSlide: function() {
this.$().carousel('prev');
},
nextSlide: function() {
this.$().carousel('next');
},
didInsertElement: function() {
this.$().carousel();
},
indicatorsView: Ember.CollectionView.extend({
tagName: 'ol',
classNames: ['carousel-indicators'],
contentBinding: 'parentView.content',
itemViewClass: Ember.View.extend({
click: function() {
var $elem = this.get("parentView.parentView").$();
$elem.carousel(this.get("contentIndex"));
},
template: Ember.Handlebars.compile(''),
classNameBindings: ['content.isActive:active']
})
}),
itemsView: Ember.CollectionView.extend({
classNames: ['carousel-inner'],
contentBinding: 'parentView.content',
itemViewClass: Ember.View.extend({
classNames: ['item'],
classNameBindings: ['content.isActive:active'],
template: Ember.Handlebars.compile('\
<img {{bindAttr src="view.content.image"}} alt=""/>\
<div class="carousel-caption">\
<h4>{{view.content.title}}</h4>\
<p>{{view.content.content}}</p>\
</div>')
})
})
});
Run Code Online (Sandbox Code Playgroud)
2 - 我不知道为什么旋转木马不包含在ember-boostrap中.