我有一个视图,不是窗口的大小,也不是窗口本身,当它调整大小时,我想比较调整大小的开始值和结束值。然而,JQ-UI 的 resize ui 对象仅包含以前的状态,而不是原始状态,因此它仅按像素抓取更改(尽管我认为这是因为我将代码放在 resize 函数中,而不是 end 函数中,但是不是真正的问题,因为一旦我知道如何将 var 返回到 Backbone View 本身,我就可以解决它)。如何从调整大小返回到主干视图中的信息? self
是全局window
对象,this
是 . 的选择器的 JQuery 结果this.el
。
define([ ... ], function( ... ){
return Backbone.View.extend({
// I also tried to use the event handlers from backbone
events : {
'resize' : 'info'
},
initialize: function(options){
if (options) { ... }
this.el = '#measure-rep-c55';
}
//Dispatch listeners
...
//Binding
this.model.bind('change', _.bind(this.render, this));
$(this.el).on('resize', this.info); // Here I am trying to attach the listener here according the API
this.render();
},
info: function(){
console.log('in info')
},
render: function(){
... //template and other stuff
// JQ-UI resizable
$(this.el).resizable({
aspectRatio: true,
start: function(e, ui) {
// alert('resizing started');
},
resize: function( event, ui ) {
// in here self = window
// and this is the JQuery object
var oldW = ui.originalSize.width;
var newW = ui.size.width;
var deltaWidth = newW - oldW;
var deltaRatio = deltaWidth/oldW;
//HOW TO SEND info (in this case var deltaRatio) back to the backbone view
//I tried getting to the function info() so that I could access the View itself from there
},
stop: function(e, ui) {
// alert('resizing stopped');
}
});
},
});
});