2013-07-16 35 views
1

强制性'我一直在努力解决这个问题,即将跳出窗口等。'Sencha设置Ext.Panel'可滚动'属性

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

忍受我,我对Sencha很新。

这里是代码的基本轮廓:

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的..它触发在正确的时间,但是显示此错误:

未捕获的类型错误:对象[对象的对象]无方法“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), 
       }); 
}, 

我的方式有问题对其他黑客开放(某种方式来设置“mousedown”期间所有内容的静态位置等),以满足基本需求。在一天结束时,我只需要屏幕在用户在#canvasSignature元素内拖动手指时不会移动。

预先感谢您!

回答

1

而不是使用Ext.get(),而不是使用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 
    }); 
} 

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

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 
    }); 
} 
+0

这工作很好!谢谢你,jprofitt,你是一个老板。 – poff

+0

作为一个方面说明,如果你不需要jQuery的其他任何东西,你的第二个可能已经工作,如果你会打包你的调用像我们在这里完成的功能。如果这就是你正在使用jQuery的所有内容,可能会有所帮助,然后将其移除并转到此路线。 – jprofitt

+0

我在其他几个地方使用jQuery。然而,我想我会再考虑一下extjs,看看我是否不能用它来替换所有的jQuery。谢谢! – poff