将数据推送到Dojo Filteringselect(带代码)

时间:2011-11-12 21:37:03

标签: php json zend-framework dojo

我对Zend& JSON,但我需要学习。我想要实现的是:使用Dojo filteringselect(带自动完成)控件,该控件链接到数据库中的zipcodes(并且跟踪ID,因此我可以将该ID作为FK存储在另一个表中(稍后)。结构是MVC。我确实得到了数据库的结果,但是我似乎无法使它发光。在filteringselect控件中没有显示任何东西。所以基本上我的数据库的结构字段需要进入filteringsselect控件并保持跟踪那个id,因为我以后需要它作为另一个表中的FK。 请帮帮我!

表:

<?php
class Application_Model_Place extends FS_Model_Popo {
protected $_fields = array(
    'id'            => NULL, 
    'zip'      => NULL, 
    'name'          => NULL, 
    'up'            => NULL, 
    'structure'     => NULL);

protected $_primaryKey = array('id');
 }

形式:

$place = new Zend_Dojo_Form_Element_FilteringSelect('Place');
$place->setLabel('Place')
    ->setAttrib('title', 'Add a place.')
    ->setAutoComplete(true)
    ->setStoreId('placeStore')
    ->setStoreType('dojox.data.QueryReadStore')
    ->setStoreParams(array('url' => '/graph/place/autocomplete'))
    ->setAttrib("searchAttr", "structure")
    ->setRequired(true);        

控制器:

class Graph_PlaceController extends Zend_Controller_Action {
public function autocompleteAction() {
    $this->_helper->viewRenderer->setNoRender();
    $this->_helper->layout->disableLayout();
    $structuur = $this->_getParam("structure", "");

    $results = FS_Model_Factory::getInstance()->place->autocomplete(array('structure like ?'=> "%".$structure."%"));
    $enc_res = array();
    foreach ($results as $value) {
        array_push($enc_res,$this->_helper->convert->toArray($value));
    }
    $this->_helper->json($enc_res);
    $data = new Zend_Dojo_Data('id', $enc_res);
    $this->_helper->autoCompleteDojo($data);
  }
}

json($ enc_res)的一个例子是:

{"id":"235","zip":"3130","name":"Betekom","up":"BETEKOM","structure":"3130 Betekom"}, {"id":"268","zip":"3211","name":"Binkom","up":"BINKOM","structure":"3211 Binkom"},{"id":"377","zip":"3840","name":"Broekom","up":"BROEKOM","structure":"3840 Broekom"},{"id":"393","zip":"1081","name":"Brussel (Koekelberg)","up":"BRUSSEL (KOEKELBERG)","structure":"1081 BRUSSEL (KOEKELBERG)"},{"id":"421","zip":"1081","name":"Bruxelles (Koekelberg)","up":"BRUXELLES (KOEKELBERG)","structure":"1081 BRUXELLES (KOEKELBERG)"},{"id":"668","zip":"3670","name":"Ellikom","up":"ELLIKOM","structure":"3670 Ellikom"},{"id":"1236","zip":"3840","name":"Jesseren (Kolmont)","up":"JESSEREN (KOLMONT)","structure":"3840 Jesseren (Kolmont)"},{"id":"1275","zip":"3370","name":"Kerkom","up":"KERKOM","structure":"3370 Kerkom"}

1 个答案:

答案 0 :(得分:0)

我认为你有几种选择:

选项1显然是最简单的......