Yii フレームワークを使い始めたばかりです。また、クリックしたときにリストのデータをモーダルに渡すのに苦労していました。私はすでにAJAXを使用していました。私のモーダルは私のリストと同じビューにあります。したがって、私のコードは基本的に次のようになります..
これは私の見解です:
<div id="view-data" class="modal viewdata-modal fade hide" data-backdrop="true">
<!-- the full data from clicked list -->
</div>
.
.
.
<div>
<!--table--list of something-->
<tr class="odd">
<td class=" "><a onclick="checkData('<?php echo $inbox_list_data['id']; ?>')" data-toggle="modal" data-target="#view-mail" ><?php $list_data['title'];?></td> else echo $msg; ?></a></td>
<td class=" "><?php $date = $list_data['date_updated']; echo date('Y / m / d',strtotime($date));?></td>
</tr>
</div>
次に、これは私のJSです:
function checkData(id) {
$.ajax({
type : 'POST',
url : "/link/data/view",
data : {'id' : id},
});
}
次に、私のコントローラーで:
public function actionIndex()
{
//getting list from db then render
}
public function actionView()
{
$this->initPage();
Helper_Site::supportMessageJS();
if(isset($_POST['id']))
{
$id = $_POST['id'];
//use the id for getting the data then ...??
}
//I cannot render since i'm passing it to modal and i dont have to refresh the page right?
$this->renderPartial('index', array('data1'=>$data1, 'data2'=>$data2, true, false);
}
では、どうすればデータをビューに戻すことができますか? しかし、私は自分のJSについても確信が持てません...
どんなアイデアでも大歓迎です。ありがとう