我使用this.store.find
在模型上加载异步数据,然后我需要激活 jQuery Slider ,但只有在商店返回滑动路径后才会激活。
我认为我需要在视图中调用this.$("#slides").slidesjs
,但在de store
返回后我无法执行此操作。有人能帮助我吗?
以下是我的代码的一部分:
App.Slide = DS.Model.extend({
src: DS.attr()
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.find('slide');
},
afterModel: function(slides) {
slides.forEach(function(item) {
item.set('src', '/img/' + item.get('src'));
});
}
});
App.IndexView = Ember.View.extend({
afterStoreReturns: function() { // i think would be some like this
this.$("#slides").slidesjs({
width: 940,
height: 528
});
}
}
非常感谢!
答案 0 :(得分:0)
我倾向于遵循两种方法。
didInsertElement
挂钩,如果未重新插入视图,则不会再次调用App.IndexView = Ember.View.extend({
didInsertElement: function() { // i think would be some like this
this.$("#slides").slidesjs({
width: 940,
height: 528
});
}
}
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.find('slide');
},
afterModel: function(slides) {
Em.run.scheduleOnce('afterRender', function(){
slides.forEach(function(item) {
item.set('src', '/img/' + item.get('src'));
});
});
}
});