2016-04-27 67 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))', 
    ), 
), 

),