2
如果在屏幕宽度发生变化时重新执行抓取,Backbone Marionette中如何执行此操作?现在,我的代码必须重新加载才能检查浏览器的宽度。当屏幕尺寸发生变化时重新执行api调用
device = getDevice(); // returns desktop or mobile based on $(window).width();
if (device === 'desktop') {
// let's pull desktop data
this.desktop = new desktopItemModel({device: 'desktop'});
this.desktopPromise = this.desktop.fetch();
}
if (device === 'mobile') {
// let's pull mobile data
this.mobile = new mobileItemModel({device: 'mobile'});
this.mobilePromise = this.mobile.fetch();
}
this.allPromise = [desktopPromise, mobilePromise];
if (device === 'desktop') {
$.when(this.desktopPromise).done(_.bind(function() {
// do your desktop stuff
}, this));
}
if (device === 'mobile') {
$.when(this.mobilePromise).done(_.bind(function() {
// do your mobile stuff
}, this));
}
'window.onresize = callFetchFunction;' – Tushar
所以看起来像是Javascript的一部分,而不是真的Backbone的权利? – devwannabe
是的,这是VanillaJS – Tushar