简体   繁体   English

如何使用Cakephp和JsHelper从表单中的选择字段中获取文本

[英]How to get the text from a select field in an form with Cakephp and JsHelper

I have the following code: 我有以下代码:

<?php
    $this->Js->get('#PoolsOptionPoolId')->event(
        'change',
        $this->Js->request(
            array(
                'controller'=>'candidates',
                'action'=>'getByType'
            ),
            array(
                'update'=>'#PoolsOptionCandidateId',
                'async' => true,
                'method' => 'post',
                'dataExpression'=>true,
                'data'=> $this->Js->serializeForm(
                    array(
                        'isForm' => true,
                        'inline' => true
                    )
                )
            )
        )
    );
?>

I'm using the JsHelper from cakephp to atualize a select field dynamically and I need to pass the text value from a selected option of the select field from my form to the controller. 我正在使用来自Cakephp的JsHelper动态地对选择字段进行实例化,并且我需要将选择字段的选定选项中的文本值从表单传递给控制器​​。 Well this function works fine if I need to pass the value from the selected option, but for my case I need pass the text. 好吧,如果我需要传递所选选项的值,则此功能可以正常工作,但就我而言,我需要传递文本。 So, is it possible to put some argument in the serializeForm function to pass the text and not the value of the selected option? 因此,是否可以在serializeForm函数中放置一些参数以传递文本,而不传递所选选项的值?

Thanks Pablo 谢谢巴勃罗

Probably not the answer you were looking for, but I would recommend just not using JsHelper at all. 可能不是您要找的答案,但是我建议您完全不要使用JsHelper。 I've always found it more complicated and often doesn't work like you want it to. 我总是发现它更复杂,并且经常无法按您希望的那样工作。 It's deprecated in CakePHP 3 because of this, I believe - it's just not any easier to hide it behind another layer of complication. 我相信,在CakePHP 3中已不推荐使用它,将它隐藏在另一层复杂性后面并不容易。

Answer: Just use standard JavaScript (or jQuery), not CakePHP's JsHelper 答案:只需使用标准JavaScript(或jQuery),而不使用CakePHP的JsHelper

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM