echo CHtml::ajaxButton (Yii::t('Listing.Listing','Associa'),
$this->createUrl('listing/addAssociation', array("id" => $model->id, "itemId"=> '5' ) ),
array('update' => '#dataToUpdate')
);
我正在使用此示例代码(并且它正在工作),将 id 和 itemId(示例中固定为“5”)发送到 addAssociation。
一切正常,但我需要为 itemId 传递 jQuery 表达式的结果。类似的东西
"itemId" = "js: $('#myDropDown option:selected').val();"
但在这种情况下,js 表达式不会被评估,并且在 actionAddAssociation 中我看到 itemId 是文字字符串:
"js: $('#myDropDown option:selected').val();"
如何允许用户选择一个组合,并将所选值传递给基于此操作的操作?
最佳答案
您必须在ajax option's data
property中传递它:
echo CHtml::ajaxButton (Yii::t('Listing.Listing','Associa'),
$this->createUrl('listing/addAssociation', array("id" => $model->id)),
array(// these are ajax options
'data' => array('itemId'=> 'js: $("#myDropDown option:selected").val()'),
// and don't use semi-colon after val(), you can also pass id here itself
'update' => '#dataToUpdate'
)
);
关于ajax - Yii 如何通过 ajaxButton 发送组合的选定值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13403432/