duanpanhuo0618 2011-11-12 21:37
浏览 82
已采纳

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

I'm quite new to Zend & JSON, however I have the need to learn. What I want to achieve is: having a Dojo filteringselect (with autocomplete) control which is linked to zipcodes from a database (and which keeps track of the ID, so I can store that ID as a FK in another table (later on). The structure is MVC. I do get results from the database, however I can't seem to make it shine. Nothing shows up in the filteringselect control. So basicly the structure field of my database needs to get into the filteringsselect control and keeping track of that id, because I need it later on as a FK in another table. Please help me out!

Table:

<?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');
 }

Form:

$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);        

Controller:

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);
  }
}

An example of json($enc_res) would be:

{"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条回答 默认 最新

  • douchushao7799 2011-11-21 17:37
    关注

    I think you have several options :

    Option 1 is obviously the easiest...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献