2016-04-27 71 views
0

我试图通过点击按钮将选定的id传递给js。yii:在js中传递参数

我的代码是这样的:

array(
    'class'=>'CButtonColumn', 
    'template'=>'{email}', 
    'buttons'=>array 
    (
     'email' => array 
     (
      'label'=>'Send an e-mail to this user', 
      'click'=>'function($data->userId){ 
       var y=confirm("Are you sure to send mail to this user?"); 
       if(y==true){ 
        window.location="todoList/sendEmail/$data->userId"; 
       } 
      }', 

     ), 

    ), 
), 

我在这里没能获得用户ID里面的js。

我能在这里做什么?

回答

2

好吧,我找到了答案,我的问题myself.My工作代码为:

array(
'class'=>'CButtonColumn', 
'template'=>'{email}', 
'buttons'=>array 
( 'email' => array 
    (
     'label'=>'Send an e-mail to this user', 
     'click'=>'function(){ 
      return confirm("Are you sure to send mail to this user?"); 

     }', 
     'url'=>'Yii::app()->createUrl("todoList/sendEmail", array("id"=>$data->userId))', 
    ), 
), 

),