0

我对 dojo 很陌生(这是我关于 stackoverflow 的第一个问题,所以放轻松:))。我正在工作中从事一个新项目,并被要求调查 dojo mobile。以下代码的目的只是为了测试 dojo mobile 在一个简单的 html 页面中提供的不同可用小部件。

我遇到了以下问题,当我在浏览器中运行此代码或将其部署到移动设备时,似乎在单击鼠标或在触摸屏上释放后应该触发的释放事件存在问题,需要注意是这仅发生在涉及拖动对象的小部件上。例如,按钮和标签栏工作正常。这仅适用于 SpinWheelDatePicker/SpinWheelTimePicker、滑块、开关等。在开发人员控制台中,我收到以下错误

在 Chrome 中:

Uncaught TypeError: Object #<klass> has no method 'remove' dojo.js:17 
_51d.disconnect dojo.js:17 
_a.onTouchEnd libs/dojo/dojox/mobile/scrollable.js:401 
_3e6 dojo.js:17 
Event.Handler.Class.create.handleEvent prototype.js:5767 
__method prototype.js:396 
responder 

在火狐中:

522.remove is not a function 
[Break On This Error] 

... function(){return _2f4.apply(window,arguments)&&_2f5.apply(window,arguments);};... 

dojo.js (line 17)( 

我正在使用 1.7.2 工具包,并且该项目被部署到工作灯服务器上。

这是代码:

<!DOCTYPE html "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
        <meta name="apple-mobile-web-app-capable" content="yes"/>

        <title>Android DOJO Test</title>

        <link rel="shortcut icon" href="images/favicon.png" />
        <link rel="apple-touch-icon" href="images/apple-touch-icon.png" />  

        <link type="text/css" rel="Stylesheet" href="css/blackbird/blackbird.css" />
        <link rel="stylesheet" href="libs/dojo/dojox/mobile/themes/android/android.css" />
        <link rel="stylesheet" href="libs/dojo/dojox/mobile/themes/common/SpinWheel.css" >
        <!-- <link rel="stylesheet" href="libs/dojo/dojox/mobile/themes/iphone/iphone.css" type="text/css" media="screen" title="no title" /> -->
        <script type="text/javascript" src="libs/blackbird/blackbird.js"></script>
        <script type="text/javascript" src="libs/dojo/dojo/dojo.js" data-dojo-config="async:true, parseOnLoad:true, mblAlwaysHideAddressBar:true"></script> 

        <script src="js/Test.js"></script>
        <script src="js/messages.js"></script>
        <script src="js/auth.js"></script>

        <script type="text/javascript">

           var jsonData = {
                    items:[
                    { src: "images/4242373_460s.jpg"},
                    { src: "images/4242618_460s.jpg"},
                    { src: "images/4242864_460s.jpg"},
                    { src: "images/icon.png"},
                    { src: "images/thumbnail.png"}
                ]
            };

            log.info('Attempting to load dojo libraries');

            require(["dojox/mobile/parser",
                     "dojo/data/ItemFileReadStore",
                     "dojox/mobile/deviceTheme", 
                     "dojox/mobile/compat",
                     "dojox/mobile",
                     "dojox/mobile/Carousel",
                     "dojox/mobile/Button",
                     "dojox/mobile/TabBar",
                     "dojox/mobile/ScrollableView",
                     "dojox/mobile/PageIndicator",
                     "dojox/mobile/SwapView",
                     "dojox/mobile/CheckBox",
                     "dojox/mobile/ToggleButton",
                     "dojox/mobile/TextBox",
                     "dojox/mobile/Switch",
                     "dojox/mobile/Slider", 
                     "dojox/mobile/RadioButton",
                     "dojox/mobile/SpinWheelDatePicker",
                     "dojox/mobile/SpinWheelTimePicker",
                     "dojox/mobile/Overlay",
                     "dojox/gauges/GlossyCircularGauge",
                     "dojox/gauges/GlossyHorizontalGauge",
                     "dojox/gauges/GlossySemiCircularGauge",
                     "dojo/on",
                     "dojo/domReady!"
                     ],
                     function(store, mobile, parser) {
                log.info('Dojo libraries loaded succesfully');
            });

            function setTabBar(to){
                if(to!=null){
                    var selectedTab = dijit.byId(to);
                    selectedTab.select();
                }
                else{
                    log.error('From or To parameter/s are empty or not a string value');
                    return; 
                }   
            }

         </script> 

    </head>
    <body onload="WL.Client.init({})" id="content" style="display: none">

            <h1 data-dojo-type="dojox.mobile.Heading">DOJO TEST APP</h1>
            <ul data-dojo-type="dojox.mobile.TabBar" id="mainTabBar">
                    <li data-dojo-type="dojox.mobile.TabBarButton" id="homeBar"     icon1="images/Aqua-Ball-Red-icon.png"       moveTo="mainView"           >Home</li>
                    <li data-dojo-type="dojox.mobile.TabBarButton" id="fadeBar"     icon1="images/Button-Blank-Green-icon.png"  moveTo="fadeView"           >Fade</li>
                    <li data-dojo-type="dojox.mobile.TabBarButton" id="slideBar"    icon1="images/Aqua-Ball-Red-icon.png"       moveTo="slideView"          >Slide</li>
                    <li data-dojo-type="dojox.mobile.TabBarButton" id="swapBar"     icon1="images/Button-Blank-Green-icon.png"  moveTo="swapViewExample"    >Swap View</li>
                    <li data-dojo-type="dojox.mobile.TabBarButton" id="formBar"     icon1="images/Aqua-Ball-Red-icon.png"       moveTo="formButtons"        >Form Buttons</li>
                    <li data-dojo-type="dojox.mobile.TabBarButton" id="carouselBar" icon1="images/Button-Blank-Green-icon.png"  moveTo="carouselView"       >Carousel</li>
                    <li data-dojo-type="dojox.mobile.TabBarButton" id="pickerBar"   icon1="images/Aqua-Ball-Red-icon.png"       moveTo="pickerView"         >Picker</li>
                    <li data-dojo-type="dojox.mobile.TabBarButton" id="overlayBar"  icon1="images/Button-Blank-Green-icon.png"  moveTo="overlayView"        >Overlay</li>
                    <li data-dojo-type="dojox.mobile.TabBarButton" id="gaugesBar"   icon1="images/Aqua-Ball-Red-icon.png"       moveTo="gaugeView"          >Gauges</li>
             </ul>

            <div data-dojo-type="dojox.mobile.View" id="mainView" selected ="true"> 
                <ul data-dojo-type="dojox.mobile.RoundRectList">
                    <li data-dojo-type="dojox.mobile.ListItem" moveTo="fadeView"        transition="fade"       onClick = "setTabBar('fadeBar');"       >Fade</li>
                    <li data-dojo-type="dojox.mobile.ListItem" moveTo="slideView"       transition="slide"      onClick = "setTabBar('slideBar');"      >Slide</li>
                    <li data-dojo-type="dojox.mobile.ListItem" moveTo="swapViewExample" transition="scaleIn"    onClick = "setTabBar('swapBar');"       >Swap View</li>
                    <li data-dojo-type="dojox.mobile.ListItem" moveTo="formButtons"     transition="scaleOut"   onClick = "setTabBar('formBar');"       >Form Buttons</li>
                    <li data-dojo-type="dojox.mobile.ListItem" moveTo="carouselView"    transition="swirl"      onClick = "setTabBar('carouselBar');"   >Carousel</li>
                    <li data-dojo-type="dojox.mobile.ListItem" moveTo="pickerView"      transition="flip"       onClick = "setTabBar('pickerBar');"     >Picker Examples</li>
                    <li data-dojo-type="dojox.mobile.ListItem" moveTo="overlayView"     transition="zoomOut"    onClick = "setTabBar('overlayBar');"    >Overlay Eaxmples</li>
                    <li data-dojo-type="dojox.mobile.ListItem" moveTo="gaugeView"       transition="zoomOut"    onClick = "setTabBar('gaugesBar');"     >Gauges</li>
                </ul>           
            </div>

            <div data-dojo-type="dojox.mobile.View" id="fadeView">
                <h2 data-dojo-type="dojox.mobile.RoundRectCategory">Fade View</h2>
            </div>

            <div data-dojo-type="dojox.mobile.View" id="slideView">
                <h2 data-dojo-type="dojox.mobile.RoundRectCategory">Slide View</h2>
            </div>  

            <div data-dojo-type="dojox.mobile.View" id="swapViewExample">

                  <div data-dojo-type="dojox.mobile.View" selected="true">

                      <div data-dojo-type="dojox.mobile.SwapView">
                        <div>
                            <h2 data-dojo-type="dojox.mobile.RoundRectCategory">Swap View Page 1</h2>
                            <img src="images/4242373_460s.jpg">
                        </div>
                      </div>

                      <div data-dojo-type="dojox.mobile.SwapView">
                        <div>
                            <h2 data-dojo-type="dojox.mobile.RoundRectCategory">Swap View Page 2</h2>
                            <img src="images/4242618_460s.jpg">
                        </div>
                      </div>

                      <div data-dojo-type="dojox.mobile.SwapView">
                        <div>
                            <h2 data-dojo-type="dojox.mobile.RoundRectCategory">Swap View Page 3</h2>
                            <img src="images/4242864_460s.jpg">
                        </div>
                      </div>
                  </div>  

                  <div data-dojo-type="dojox.mobile.PageIndicator" fixed="bottom"></div>
            </div>

            <div data-dojo-type="dojox.mobile.View" id="formButtons">   

                  <ul data-dojo-type="dojox.mobile.RoundRectList" shadow="true">
                    <span>Button</span><br> 
                        <div align="right"><button data-dojo-type="dojox.mobile.Button" data-dojo-props='label:"Click me!", onClick:function(e){ alert("button clicked");return true; }'></button></div>
                  </ul>

                    <ul data-dojo-type="dojox.mobile.RoundRectList" shadow="true">
                    <span>CheckBox</span><br> 
                        <div align="right"><input data-dojo-type="dojox.mobile.CheckBox" type="checkbox" data-dojo-props='onChange:function(checked){ alert("checked state changed to " + checked); },checked:true' /></div>
                     </ul>      

                    <ul data-dojo-type="dojox.mobile.RoundRectList" shadow="true">
                    <span>Radio Button</span><br> 
                         <div align="right"><input type="radio" data-dojo-type="dojox.mobile.RadioButton" checked="true"  name="radioGroup" value="yes" /><input type="radio" data-dojo-type="dojox.mobile.RadioButton" checked="false" name="radioGroup" value="no" /></div>
                     </ul>      

                    <ul data-dojo-type="dojox.mobile.RoundRectList" shadow="true">
                    <span>Slider</span><br> 
                        <div align="right"><input type="range" style="width:200px;" data-dojo-type="dojox.mobile.Slider" value="10" max="20" /></div>
                     </ul>      

                    <ul data-dojo-type="dojox.mobile.RoundRectList" shadow="true">
                    <span>Switch</span><br> 
                        <div align="right"><div data-dojo-type="dojox.mobile.Switch" align="right"></div></div>
                     </ul>  

                    <ul data-dojo-type="dojox.mobile.RoundRectList" shadow="true">
                    <span>Toggle Button</span><br> 
                        <div align="right"><button data-dojo-type="dojox.mobile.ToggleButton" checked="true">Toggle me</button></div>
                    </ul>         
            </div>  

            <div data-dojo-type="dojox.mobile.View" id="carouselView">
                <div data-dojo-type="dojox.mobile.ScrollableView" >
                    <span data-dojo-type="dojo.data.ItemFileReadStore" id="store1" data-dojo-props="data:jsonData"></span> 
                    <div id="carousel1" data-dojo-type="dojox.mobile.Carousel" store = "dijit.registry.byId('store1')" data-dojo-props="height:'500px', navButton:'true' , numVisible:2, title:'Photo Gallery'"></div>
               </div>
            </div>  

            <div data-dojo-type="dojox.mobile.View" id="pickerView">              
                  <h2  data-dojo-type="dojox.mobile.Heading">Date Picker</h2>
                    <div align="center"><div id="spin1" data-dojo-type="dojox.mobile.SpinWheelDatePicker" align="center"></div></div>

                  <h2  data-dojo-type="dojox.mobile.Heading">Time Picker</h2>
                    <div align="center"><div id="spin2" data-dojo-type="dojox.mobile.SpinWheelTimePicker" align="center"></div></div>
            </div>

            <div data-dojo-type="dojox.mobile.View" id="overlayView">
                <div align="center"><button data-dojo-type="dojox.mobile.Button" onClick="dijit.registry.byId('customPicker').show()" data-dojo-props='label:"Select date"'></button></div>
                  <div id="customPicker" data-dojo-type="dojox.mobile.Overlay">         

                    <h1 data-dojo-type="dojox.mobile.Heading" label="Custom Picker">
                        <div data-dojo-type="dojox.mobile.ToolBarButton" label="Done" class="mblColorBlue" style="width:45px;float:right;" onClick="dijit.registry.byId('customPicker').hide()"></div>
                    </h1>
                    <div id="spin3" data-dojo-type="dojox.mobile.SpinWheelDatePicker"></div>                    
                  </div>    
           </div>

             <div data-dojo-type="dojox.mobile.View" id="gaugeView">
                <div data-dojo-type="dojox.mobile.View" id="gaugeMainView">
                <div align="center"><h2 data-dojo-type="dojox.mobile.Heading">Guages</h2></div>
                    <ul data-dojo-type="dojox.mobile.RoundRectList">
                        <li data-dojo-type="dojox.mobile.ListItem" moveTo="glossyCircView"      transition="fade"  onClick = >Glossy Circular</li>
                        <li data-dojo-type="dojox.mobile.ListItem" moveTo="glossySemiView"      transition="slide" onClick = >Glossy Semi Circular</li>
                        <li data-dojo-type="dojox.mobile.ListItem" moveTo="glossyHorView"       transition="scaleIn" onClick = >Glossy Horizontal</li>
                        <li data-dojo-type="dojox.mobile.ListItem" moveTo="simpleAnalog"        transition="scaleOut" onClick = >Simple Analog Gauges</li>
                    </ul>   
                </div>
                <div data-dojo-type="dojox.mobile.View" id="glossyCircView">
                    <h1 data-dojo-type="dojox.mobile.Heading" back="Gauge View" moveTo="gaugeMainView" onClick="console.log('Going back');">Glossy Circular</h1>
                        <div align="center"><div id="CircularGauge" background='{color : "rgba(0,0,0,0)"}'useTooltip='false'  data-dojo-type='dojox.gauges.GlossyCircularGauge' width='200' height='200' value='20'></div></div>
                </div>

                <div data-dojo-type="dojox.mobile.View" id="glossySemiView">
                    <h1 data-dojo-type="dojox.mobile.Heading" back="Gauge View" moveTo="gaugeMainView" onClick="console.log('Going back');">Glossy Semi Circular</h1>
                        <div align="center"><div id="CircularGauge1" background='{color : "rgba(0,0,0,0)"}'useTooltip='false'  data-dojo-type='dojox.gauges.GlossySemiCircularGauge' width='200' height='200' value='20'></div></div>
                </div>

                <div data-dojo-type="dojox.mobile.View" id="glossyHorView">
                    <h1 data-dojo-type="dojox.mobile.Heading" back="Gauge View" moveTo="gaugeMainView" onClick="console.log('Going back');">Glossy Horizontal</h1>
                        <div align="center"><div id="CircularGauge2" background='{color : "rgba(0,0,0,0)"}'useTooltip='false'  data-dojo-type='dojox.gauges.GlossyHorizontalGauge' width='400' height='30' value='20'></div></div>
                </div>

                <div data-dojo-type="dojox.mobile.View" id="simpleAnalog">
                    <h1 data-dojo-type="dojox.mobile.Heading" back="Gauge View" moveTo="gaugeMainView" onClick="console.log('Going back');">Simple Analog Gauges</h1>

                </div>
            </div> 
    </body>
</html>
4

1 回答 1

1

我认为您遇到了 Worklight JavaScript 库(更具体地说是prototype.js)和 Dojo 之间的已知不兼容问题。

您的确切问题是prototype.js为所有元素添加了一个“on”方法,但不幸的是,这个方法与Dojo期望的不兼容(Dojo希望'on'返回一个带有remove()方法的对象,而prototype.js返回一个带有 stop() 方法的对象)。

作为一种解决方法,请尝试将以下脚本添加到您的页面:

    <script type="text/javascript">
        // Fix incompatibility between Prototype and Dojo
        Event.Handler.prototype.remove = function(){
            this.stop();
        };
    </script>

您必须在 Worklight 将插入prototype.js 的位置之后添加它,在您的页面中,我会说auth.js 和您的主脚本之间应该是正确的位置。

于 2012-06-05T14:35:24.190 回答