2011-10-26 106 views
0

我正在开发与zend框架的应用程序,我想添加dojo框架。 我已经做了以下内容: bootstrap.php中:Zend框架与dojo

public function _initViewHelpers() 
{ 
    $this->bootstrap('layout'); 
    $layout = $this->getResource('layout'); 
    $view = $layout->getView(); 

    $view->addHelperPath('Zend/Dojo/View/Helper', 
            'Zend_Dojo_View_Helper'); 

    $view->dojo()->enable(); 
} 

我layout.phtml

<?php echo $this->doctype() ?> 
<html> 
    <head> 
    <?php echo $this->headTitle() ?> 
    <?php echo $this->headMeta() ?> 
    <?php echo $this->headLink() ?> 
    <?php echo $this->headStyle() ?> 
    <?php if ($this->dojo()->isEnabled()){ 
     $this->dojo()->setLocalPath('/js/dojo/dojo.js') 
        ->addStyleSheetModule('dijit.themes.claro'); 
     echo $this->dojo(); 
     } 
    ?> 
    <?php echo $this->headScript() ?> 
</head> 
<body class="claro"> 
    <?php echo $this->layout()->content ?> 
    <?php echo $this->inlineScript() ?> 
</body> 

最后我index.phtml:

<script type="text/javascript"> 

dojo.addOnLoad(function() { 
    // our test data store for this example: 
    var store4 = new dojo.store.JsonRest({ 
     target: '/guestbook/test' 
    }); 

    storeData = new dojo.data.ItemFileReadStore( 
      { data:store4 } 
     ); 

    // set the layout structure: 
    var layout4 = [{ 
     field: 'Title', 
     name: 'Title of Movie', 
     width: '200px' 
    }, 
    { 
     field: 'Year', 
     name: 'Year', 
     width: '50px' 
    }, 
    { 
     field: 'Producer', 
     name: 'Producer', 
     width: 'auto' 
    }]; 

    // create a new grid: 
    var grid4 = new dojox.grid.DataGrid({ 
     query: { 
      Title: '*' 
     }, 
     store: storeData, 
     clientSort: true, 
     rowSelector: '20px', 
     structure: layout4 
    }, 
    document.createElement('div')); 

    // append the new grid to the div "gridContainer4": 
    dojo.byId("gridContainer4").appendChild(grid4.domNode); 

    // Call startup, in order to render the grid: 
    grid4.startup(); 
}); 

<div id="gridContainer4" style="width: 100%; height: 100%;"> 
</div> 

<?php // setup required dojo elements: 
$this->dojo()->enable() 
      ->setDjConfigOption('parseOnLoad', true) 
      ->requireModule('dojo.store.JsonRest') 
      ->requireModule('dojo.data.ObjectStore') 
      ->requireModule('dojo.data.ItemFileReadStore') 
      ->requireModule('dojox.data.QueryReadStore') 
      ->requireModule('dojox.grid.DataGrid') 
      ->addStyleSheet('/js/dojox/grid/resources/claroGrid.css') 
      ->addStyleSheet('/js/dojox/grid/resources/Grid.css'); ?> 

当我试图访问页面localhost /留言板,页面呈现,但没有datagrid,这就像没有启用JavaScript ... url /留言板/测试返回一个json对象。 而在firebug中,没有javascript错误,dojo.js被加载,dojo模块和css也一样。 我不明白发生了什么事! 谢谢:)

回答

0

您正在创建网格并将其放入未连接的div。相反,附加网格gridContainer4

// create a new grid: 
var grid4 = new dojox.grid.DataGrid({ 
    query: { 
     Title: '*' 
    }, 
    store: storeData, 
    clientSort: true, 
    rowSelector: '20px', 
    structure: layout4 
}, 
dojo.byId("gridContainer4"));