如何设置快速搜索初始值?

发布于 2025-01-07 20:29:47 字数 184 浏览 4 评论 0原文

我想在哪里放置一个初始值。 我已经看到快速搜索有“q”元素,但我无法访问它,例如,这找不到 q 元素:

$quickSearch->getElement('q');

How can I access the fastsearch to set an initial value?

where I want tu put an initial value.
I have seen that quicksearch has 'q' element but I can't access it, for example this does not find the q element:

$quickSearch->getElement('q');

How can I access the quicksearch in order to set an initial value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尤怨 2025-01-14 20:29:47

查看它的来源可以帮助您找到问题。 Agile Toolkit 的设计方式是开发人员应该利用源代码的知识。

QuickSearch 是从 Filter 派生的,而 Filter 是从 Form 派生的,所以应该有 addField 的地方。查看 QuickSearch,您会在recallAll() 函数中找到它。没有对此函数的调用,因此我们应该查看父类 - Filter。

Filter 在 api 中设置一个钩子,在初始化完成后调用recallAll。这意味着要能够访问该字段,您可以重新定义方法或自己添加挂钩。

挂钩:

$this->api->addHook('post-init',function() use($quickSearch){
    $quickSearch->getElement('q')->set('hello');
});

扩展

class MyQuicksearch extends QuickSearch {
    function recallAll(){
        parent::recallAll();
        $this->getElement('q')->set('hello');
    }
}

最后,您可以利用了解recallAll从何处加载默认值的优势,只需执行以下操作:

$quicksearch->memorize('q','hello');

Looking at the source of it can help you find things out. Agile Toolkit is designed in a way where developer should take advantage of the knowledge of the source code.

QuickSearch is derived from Filter which is derived from Form, so there should be addField somewhere. Looking at the QuickSearch, you'll find it inside recallAll() function. There are no calls to this functions so we should look into the parent class - Filter.

Filter sets up a hook in api to call recallAll after initialization have been finished. That means to be able to access the field you can either redefine a method or add a hook yourself.

Hook:

$this->api->addHook('post-init',function() use($quickSearch){
    $quickSearch->getElement('q')->set('hello');
});

Extending

class MyQuicksearch extends QuickSearch {
    function recallAll(){
        parent::recallAll();
        $this->getElement('q')->set('hello');
    }
}

Finally you can take advantage of knowing where recallAll is loading their default values from and simply do this:

$quicksearch->memorize('q','hello');
我不会写诗 2025-01-14 20:29:47

为了解决这个问题,我们首先要了解QuickSearch类的Search Field是如何添加到Grid Basic类中的。因此,通过研究源代码,我们可以看到:

  1. QuickSearch 类不会跟踪(或保存其 PUBLIC 引用)Form_Field q
  2. Form_Field q 添加在网格的渲染阶段

知道这些,我们现在可以继续添加对地址项 #1 的修改。

首先,我们需要添加一个变量来跟踪 QuickSearch 类中的 Form_Field q

 var $search_field=null; // add this line (1)
 function recallAll(){
    $ff=$this->addField('line','q','');
    $this->search_field=$ff; // and this line (2)
    parent::recallAll();
    :
    :
 }

其次,为了解决第 2 项,在定义网格的页面上,我们需要添加一个后续挂钩,例如:

 class page_gridsearchtest extends Page {
    var $search=null;

    function init() {
       parent::init();

       $g = $this->add('MVCGrid');
       $g->setModel('Employees');
       if($g){
          $this->search=$g->addQuickSearch(array('fullname'));
          if($this->search)
             $this->api->addHook('post-init',array($this,'MyHook')); // add hook
       }
    }
    function MyHook(){ // hooked method
       if($this->search->search_field) {
          if($this->search->search_field->get()=='')
             $this->search->search_field->set('Juan'); // set initial search if blank
          $this->search->search_field->setCaption('Employee Name Search');
       }
    }
 }

这将在快速搜索字段旁边设置一个CAPTION,并在搜索字段为空时添加DEFAULT搜索文本。

如果这只是一次性的事情,那么这可能作为一种快速修复很有用,因为直接对库源进行更改是非常不正统的,并且不遵循 ATK 所提倡的扩展和子类化的 OOP 概念。

to address this, we must first understand how the Search Field of the QuickSearch Class is added to the Grid Basic Class. so upon investigation of the source code, we can see that:

  1. QuickSearch Class does not track (or save a PUBLIC reference of) the Form_Field q
  2. Form_Field q is ONLY added DURING the Rendering phase of the grid

knowing these, we can now proceed adding the modifications to address item #1.

first, we need to add a variable to track the Form_Field q in the QuickSearch Class:

 var $search_field=null; // add this line (1)
 function recallAll(){
    $ff=$this->addField('line','q','');
    $this->search_field=$ff; // and this line (2)
    parent::recallAll();
    :
    :
 }

second, to address item #2, on our page where the grid is defined, we need add a follow-up hook, example:

 class page_gridsearchtest extends Page {
    var $search=null;

    function init() {
       parent::init();

       $g = $this->add('MVCGrid');
       $g->setModel('Employees');
       if($g){
          $this->search=$g->addQuickSearch(array('fullname'));
          if($this->search)
             $this->api->addHook('post-init',array($this,'MyHook')); // add hook
       }
    }
    function MyHook(){ // hooked method
       if($this->search->search_field) {
          if($this->search->search_field->get()=='')
             $this->search->search_field->set('Juan'); // set initial search if blank
          $this->search->search_field->setCaption('Employee Name Search');
       }
    }
 }

this will set a CAPTION beside the QuickSearch field and add a DEFAULT search text if the search field is empty.

if this is just a one-time thing, then this may be useful as a quick fix because directly making changes to the library source is very unorthodoxed and does not follow the OOP concept of extending and sub-classing as promoted by ATK.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文