0

如何将 zend_db_table_rowset 对象转换为 javascript 数组

$db=new Application_Model_DbTable_Books();
        $result=$db->showBooks();

展示书籍:

class Application_Model_DbTable_Books extends Zend_Db_Table_Abstract
{

    protected $_name = 'books';
    protected $_primary = 'id';
    public function showBooks(){
            return $this->fetchAll();


}

我想将结果集转换为类似这样的东西:

  var aDataSet = [
                ['Trident','Internet Explorer 4.0','Win 95+','4','X'],
                ['Trident','Internet Explorer 5.0','Win 95+','5','C'],
                ['Trident','Internet Explorer 5.5','Win 95+','5.5','A'],
                ['Trident','Internet Explorer 6','Win 98+','6','A']];
4

1 回答 1

1

JSON 更适合此类操作

内部控制器

$db=new Application_Model_DbTable_Books();
$result=$db->showBooks();    
$this->view->booksJson = Zend_Json::encode($result);

内部视图脚本

var aDataSet = JSON.parse(<?php echo $this->booksJson;?>);
于 2012-08-09T08:10:57.273 回答