我刚刚开始使用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...
任何想法都非常感谢。谢谢
你必须在 ajax 完成后更新你的视图容器。
function checkData(id) {
$.ajax({
type : 'POST',
url : "/link/data/view",
data : {'id' : id},
}).done(function( data ) {
$("#view-data").html(data);
}
});
}