我有一個視圖,不是窗口的大小,也不是窗口本身,當它調整大小時,我想比較的開始和結束值調整。然而,JQ-UI的調整ui對象的大小隻包括以前的狀態,而不是原始狀態,所以它只是通過像素來獲取更改(儘管我認爲這是因爲我將代碼放在resize函數中,而不是最終函數,但是不是真正的問題,因爲一旦我知道如何將var返回到Backbone View本身,我就可以解決它)。如何將調整大小內的信息返回到骨幹視圖? self
是全球的window
對象,並且this
是選擇器this.el
的JQuery結果。JQuery UI可調整大小調整事件綁定/調整大小事件到主幹視圖
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');
}
});
},
});
});
我沒有得到這個工作,但它幫助我走向正確的方向。我非常感謝你的解釋!我最終在通話中設置了範圍。我不知道我爲什麼(或者我的團隊無法讓你的例子在我們的工作)。再次感謝! –
@chrisFrisina現在我再次查看你的代碼,很可能是因爲你搞亂了初始化。你不應該在初始化方法中設置'this.el'。它在建造時應該通過。這可能是很多事情無法正常工作的原因。 – Andrew