2013-09-27 72 views
1

我想知道爲什麼dojo沒有響應元素的變化? 我做了一個簡單的例子來展示我的問題!當我使用on(window,"resize", function());但我不知道爲什麼上面的例子中不起作用呼叫調整大小方法在dojo

<html > 
<head> 
    <script>dojoConfig = {parseOnLoad: true}</script> 
    <script src='../dojo/dojo.js'></script> 
    <script> 
     require([ 
      "dijit/layout/BorderContainer", 
      "dijit/layout/ContentPane" 
     ]); 
     require(["dojo/dom","dojo/on","dojo/domReady!"], function(dom, on){ 

      on(dom.byId("tester"),"resize", function() { console.log('window on resize') }); 

     }); 
    </script> 
</head> 
<body> 
<div data-dojo-type="dijit/layout/ContentPane" style="width: 50%;" > 
    <div data-dojo-type="dijit/layout/BorderContainer" id="tester"> 
    </div> 
</div> 
</body> 
</html> 

,一切工作正常。

+0

使用BorderContainer調整大小的方法是微件的方法,而不是れ的方法。您正在使用返回dom節點的dom.byId(「tester」),請嘗試使用「dijit/registry」.byId來獲取小部件變量。 –

+0

在答案中查看我的「使用方面而不是」。 –

回答

0

嘗試此(使用方面,而不是在):

<html > 
<head> 
    <script>dojoConfig = {parseOnLoad: true}</script> 
    <script src='../dojo/dojo.js'></script> 
    <script> 
     require([ 
      "dijit/layout/BorderContainer", 
      "dijit/layout/ContentPane" 
     ], function(BC, CP){ 
     require(["dojo/aspect","dojo/domReady!"], function(aspect){ 

      var bc= new BC({}, "tester"); 

      bc.startup(); 

      aspect.after(bc, "resize", function() { console.log('window on resize') }); 


     }); 
     });  
    </script> 
</head> 
<body> 
    <div id="tester" style="width: 50%;height:100%;"> 
    </div> 
</body> 
</html>