【问题标题】:Get value of selectbox with JsHelper in CakePHP在 CakePHP 中使用 Js Helper 获取选择框的值
【发布时间】:2011-06-15 04:45:50
【问题描述】:

我有一个选择框,我想用它来 Ajax 更新页面上的一些其他内容。所以我使用 JsHelper (jQuery) 绑定了一个事件处理程序,如下所示:

<?php
echo $this->Form->select('car', $cars);
$this->Js->get("#car");
$this->Js->event('change', $this->Js->request(array(
    'controller'  => 'cars',
    'action'      => 'view', 
    ???,
    array('async' => true, 'update' => '#car-view', 'evalScripts'  => true),
    true
));
?>

但是我怎样才能获得选择框的值作为参数发送给汽车控制器(在上面代码中的“???”处)?

我可以在 javascript 中做所有事情,但是有什么方法可以在 cake 中做到这一点?

【问题讨论】:

    标签: javascript cakephp helper drop-down-menu


    【解决方案1】:

    我想你正在寻找这个:

    $this->Js->get('#selectbboxid1')->event('change', 
            $this->Js->request(array(
                'action' => 'function'), array(
                    /*'before' => 'showLoader();',
                    'success' => 'hideLoader();',*/
                    'update' => '#selectboxid2',
                    'dataExpression'=>TRUE, 
                    'method'=>'POST',
                    'async'=>TRUE,
                    'data' => $js->serializeForm(array('isForm' => TRUE, 'inline' => TRUE))  )));
    

    【讨论】:

      【解决方案2】:

      老实说,我前一阵子为此苦苦挣扎。我找不到任何可行的方法,所以我最终只使用了直接的 javascript 路线。

      【讨论】:

      • 我也一直在尝试解决这个问题,但仍然没有发现任何有用的东西。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-31
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-30
      相关资源
      最近更新 更多