我在 zend 中有一个视图,其中我们有提交条目的表单,在底部我们列出了以前的条目。当我们点击搜索按钮时,我已经应用了搜索功能并且它工作正常。现在我想要的是使用 getJSON 事件对 keyup 事件应用搜索,以便我们可以立即搜索内容。
我为搜索添加了两个条件...使用搜索按钮单击进行搜索。
if($req->isPost()) {
{
//$ajaxPostedData = $req->getPost();
$ajaxPostedData = $req->getParams();
//echo $ajaxPostedData['search_term'];
$select->where("ma_heading like '%".$ajaxPostedData['search_term']."%'");
//$select->where($val)
//echo $select->__toString();die;
//print_r($data = $db_model->fetchAll($select));
//die;
//echo $select->__toString();
return $data = $db_model->fetchAll($select);
# Paging section
$paginator = Zend_Paginator::factory($data);
$paginator->setItemCountPerPage(PAGING_RESULT_PER_PAGE);
$paginator->setCurrentPageNumber($page);
$paginator->setPageRange(PAGING_PAGES_RANGE_PER_PAGE);
$this->view->data = $paginator;
//$this->_helper->P($ajaxPostedData);die;
//
}
和 keyup 事件
if($req->isXmlHttpRequest())
{
//$ajaxPostedData = $req->getPost();
$ajaxPostedData = $req->getParams();
//echo $ajaxPostedData['search_term'];
$select->where("ma_heading like '%".$ajaxPostedData['search_term']."%'");
//$select->where($val)
//echo $select->__toString();die;
//print_r($data = $db_model->fetchAll($select));
//die;
//echo $select->__toString();
return $data = $db_model->fetchAll($select);
# Paging section
$paginator = Zend_Paginator::factory($data);
$paginator->setItemCountPerPage(PAGING_RESULT_PER_PAGE);
$paginator->setCurrentPageNumber($page);
$paginator->setPageRange(PAGING_PAGES_RANGE_PER_PAGE);
$this->view->data = $paginator;
//$this->_helper->P($ajaxPostedData);die;
//
}
但是当我们在 keyup 上搜索内容时,内容不会动态替换。
请帮助我如何在 zend 中应用 keyup 搜索。
这是我用来发送请求的 jQuery 脚本
jQuery('#txt_heading_filer').keyup(function() {
var heading = jQuery('#txt_heading_filer').val();
$.getJSON('admin/admin/announcements/search_term/'+heading, function() {
});
});
这是需要在搜索时刷新的表
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="top-table-bg">
<tr>
<th width="" align="left"><?php echo $obj_trans->_('heading'); ?></th>
<th width="20%" align="left"><?php echo $obj_trans->_('expiry date'); ?></th>
<th width="10%" align="center"><?php echo $obj_trans->_('publish/unpublish'); ?></th>
<th width="10%" align="center"><?php echo $obj_trans->_('action'); ?></th>
</tr>
<?php
foreach($data_arr as $key => $data) { ?>
<tr>
<td align="left" class="name" ><span><?php echo $data[PREFIX_MASTER_ANNOUNCEMENTS . 'heading']; ?></span></td>
<td align="left" class="name">
<?php echo (!empty($data[PREFIX_MASTER_ANNOUNCEMENTS . 'expiry_date'])) ? date("j", strtotime($data[PREFIX_MASTER_ANNOUNCEMENTS . 'expiry_date'])).'<sup>'.date("S", strtotime($data[PREFIX_MASTER_ANNOUNCEMENTS . 'expiry_date'])).'</sup> '.date("M, Y", strtotime($data[PREFIX_MASTER_ANNOUNCEMENTS . 'expiry_date'])) : "N/A"; ?>
</td>
<td align="center">
<?php Admin_View_Helper_GeneralHelper::status_icon($data[PREFIX_MASTER_ANNOUNCEMENTS . 'status']); ?></td>
<td align="center">
<a href="javascript:;" class="info_tooltip update_data" title="Edit" rel="<?php echo $data[PREFIX_MASTER_ANNOUNCEMENTS . 'id']; ?>" id="link_edit"><?php echo $this->img("img/admin/icons/edit.png", array('id' => 'icon_edit')) ?></a>
<a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'announcements', 'do' => 'delete', 'item' => $data[PREFIX_MASTER_ANNOUNCEMENTS . 'id'])); ?>" class="info_tooltip delete_data" title="Delete" rel="<?php echo $data[PREFIX_MASTER_ANNOUNCEMENTS . 'id']; ?>" id=""><?php echo $this->img("img/admin/icons/delete.png", array('id' => 'icon_delete')) ?></a>
</td>
</tr>
<?php } ?>
</table>