1

强制性“我整天都在研究这个问题,快要跳出窗户等等。”

我正在开发 Sencha Touch 2 应用程序。在当前视图中,我想禁用用户在元素内单击和拖动时的滚动功能。这个元素是他们正在绘制的画布,所以显然我不希望页面在他们绘制时上下移动!

忍受我,我对煎茶很陌生。

以下是代码的基本概要:

    Ext.define('App.view.Canvas', {
    extend: "Ext.Panel",
    id: "panel",
    alias: "widget.canvas",
    requires: ['Ext.ux.Fileup'],

    config: {
        styleHtmlContent: true,
        scrollable: true,
        tpl:"<!-- a bunch of html -->"+
                "<div id='canvasDiv'></div>"+
            "<!-- more html -->",

        items: [{
            xtype: "toolbar",
            title: "Canvas",
            docked: "top",
        }],

        listeners: [{
            some listeners
        }, {
            event: "show",
            fn: "onShow",
        }],
    },

    onShow: function() {

        // where I am trying to change the scrollable bit

    },
});

现在这是我尝试过的事情:

我认为这个不起作用,因为我正在混合 jquery 和 extjs ...它在正确的时间触发,但显示此错误:

未捕获的类型错误:对象 [object Object] 没有方法“setScrollable”

onShow: function () {
// #canvasSignature is the id of the canvas that is loaded in the controller and placed in #canvasDiv
$("#canvasSignature").mousedown(function() {
                Ext.get('panel').setScrollable(false); //attempting to reference panel
            }).bind('mouseup mouseleave', function() {
                Ext.get('panel').setScrollable(true); //attempting to reference panel
            });
}

然后我尝试了这个,但是基于控制台错误(TypeError:无法读取未定义的属性'fn')我认为我使用get()的方式有问题

onShow: function () {
    Ext.get("canvasSignature").on({
                    dragstart: Ext.get('panel').setScrollable(false),
                    dragend: Ext.get('panel').setScrollable(true),
                });
},

如果它们满足基本需求,我愿意接受其他黑客(在“鼠标按下”等期间设置所有东西的静态位置的某种方式)。归根结底,当用户在#canvasSignature 元素中拖动手指时,我只需要屏幕不动。

先感谢您!

4

1 回答 1

1

Ext.get()您可能只想引用视图本身,而不是使用返回 DOM 元素而不是 Sencha 组件的setScrollable().

onShow: function () {
    var me = this;
    // #canvasSignature is the id of the canvas that is loaded in the controller and placed in #canvasDiv
    $("#canvasSignature").mousedown(function() {
        me.setScrollable(false); //attempting to reference panel
    }).bind('mouseup mouseleave', function() {
        me.setScrollable(true); //attempting to reference panel
    });
}

您也可以覆盖Panel'sinitialize()方法,而不需要附加监听器。

initialize: function () {
    this.callParent(arguments);

    var me = this;
    // #canvasSignature is the id of the canvas that is loaded in the controller and placed in #canvasDiv
    $("#canvasSignature").mousedown(function() {
        me.setScrollable(false); //attempting to reference panel
    }).bind('mouseup mouseleave', function() {
        me.setScrollable(true); //attempting to reference panel
    });
}
于 2013-07-16T01:52:54.793 回答