1
我正在使用yii,並且在產品從中刪除後我想更新我的clistview。 這裏是CListView中部件代碼當在yii中刪除記錄時更新CListView
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'viewData'=>array('exhibitorId'=>$exhibitorId),
'id'=>'productView',
'itemView'=>'_productView',
'sortableAttributes'=>array(
'productName',
'productType',
'productBrand',
'description'
)
)); ?>
這裏是_productView
<b><?php echo CHtml::encode(Products::model()->getAttributeLabel('creationDate')); ?>:</b>
<?php echo CHtml::encode($data['creationDate']); ?>
<br />
<b><?php echo CHtml::encode(Products::model()->getAttributeLabel('updatedBy')); ?>:</b>
<?php echo CHtml::encode($data['updatedBy']); ?>
<br />
<?php echo CHtml::ajaxLink('Delete', array('deleteMyThisProduct', 'product'=>$data['productId'],'exhibitor'=>$exhibitorId),
array(
"beforeSend" => 'js:function(){if(confirm("Are you sure you want to delete?"))return true;}',
"success"=>'js:function(data){'
. '$.fn.yiiListView.update("productView");'
. '}',
"type"=>'post',
)); ?>
這裏就是AJAX鏈接進入
public function actionDeleteMyThisProduct($product,$exhibitor)
{
if(Yii::app()->request->isAjaxRequest)
{
$productId=(int)$product;
$exhibitorId=(int)$exhibitor;
if($productId !== 0 && $exhibitorId !== 0)
{
$deleteProduct= Exhibitorproducts::model()->loadRecordsByexhibitorIdAndProductId($exhibitorId, $productId);
ProductPhotos::model()->deleteAllPhotosByExhibitorIdAndProductId($exhibitorId, $productId);
if(!empty($deleteProduct))
{
$deleteProduct->delete();
}
}
}
}
問題的行動: - 現在的問題是,我第一次從clistview中刪除產品。它非常好地刪除產品並更新列表。但之後,當我點擊下一個產品的刪除鏈接時,它什麼都不做。那麼我該如何克服這個問題呢?
雖然我解決了這個問題昨天才用同樣的解決方案你給了。反正謝謝你的回答和幫助我......乾杯:) –