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 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含