gpt4 book ai didi

javascript - JQuery UI resizable Resize 事件绑定(bind)/on resize 事件到 Backbone View

转载 作者:行者123 更新时间:2023-11-30 08:50:25 30 4
gpt4 key购买 nike

我有一个 View ,不是窗口的大小,也不是窗口本身,当它调整大小时,我想比较调整大小的开始值和结束值。然而,JQ-UI 的 resize ui 对象只包含以前的状态,而不是原始状态,所以它只是按像素获取变化(尽管我认为这是因为我将代码放在调整大小函数中,而不是结束函数中,但是这不是真正的问题,因为一旦我知道如何将 var 返回到 Backbone View 本身,我就可以解决它)。如何将调整大小内的信息返回到主干 View ? self 是全局 window 对象,thisthis.el 选择器的 JQuery 结果。

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');
}
});
},
});
});

最佳答案

不要在可调整大小的调用中创建监听器,使用事件哈希来监听更改,然后您可以直接从回调访问您的 View 。

events : {
'resizestart' : 'start',
'resizestop' : 'stop',
'resize' : 'resize'
},

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 ) {
// this is the View
var oldW = ui.originalSize.width;
var newW = ui.size.width;
var deltaWidth = newW - oldW;
var deltaRatio = deltaWidth/oldW;
},
stop: function(e, ui) {
// alert('resizing stopped');
}

关于javascript - JQuery UI resizable Resize 事件绑定(bind)/on resize 事件到 Backbone View,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18390420/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com