我想通过单击CGridView CButtonColumn视图按钮打开CJuiModel,因为我的CGridView和CJuiModel如下: -
<?php
$dataProvider = new CArrayDataProvider($model->exhibitorLocation, array(
'keys' => array('productId'),
));
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'id' => 'exhibitor-location-grid',
'summaryText' => false,
'pager' => array(
'class' => 'CLinkPager',
'header' => false,
),
'columns' => array(
array(
'header' => 'S No.',
'value' => '++$row',
),
array(
'header' => 'Hall No',
'value' => '$data->location->hallNo',
),
array(
'header' => 'Stand No',
'value' => '$data->standNo',
),
array(
'class' => 'CButtonColumn',
'header' => 'Manage',
'template' => '{view}{delete}',
'buttons' => array(
'view' => array(
'imageUrl' => $this->module->assetsUrl . "/images/info_icon.png",
'options' => array('class' => 'exb-location'),
'url' => 'Yii::app()->createUrl("admin/venuemap/viewExbLocation", array("exbLocId"=>$data->primaryKey))',
),
'delete' => array(
'imageUrl' => $this->module->assetsUrl . "/images/delete_icon.png",
'url' => 'Yii::app()->createUrl("admin/venuemap/deleteExbLocation", array("exbLocId"=>$data->primaryKey))',
),
),
'htmlOptions' => array(
'style' => 'width:100px;float:center'
)
),
),
'rowCssClassExpression' => '($row%2 ? "visit2" : "visit1")',
'itemsCssClass' => 'visitor_list',
'htmlOptions' => array(
)
));
?>
<div class="name_field">Hall No<span>*</span></div>
<?php echo CHtml::dropDownList('hall-no', '', CHtml::listData(Venuemap::model()->findAll(), 'locationId', 'hallNo'), array('class' => 'name_input2', 'id' => 'hall-no')); ?>
<div class="name_field">Stand No</div>
<?php echo CHtml::textField('Stand No', '', array('class' => 'name_input', 'id' => 'stand-no')); ?>
<?php
echo CHtml::ajaxLink("Add Location", Yii::app()->createUrl('admin/venuemap/addExbLocation'), array(
'type' => 'post',
'data' => array(
'exhibitorId' => $model->exhibitorId,
'standNo' => 'js: $("#stand-no").val()',
'locationId' => 'js: $("#hall-no").val()'
),
'success' => 'function(html){ $.fn.yiiGridView.update("exhibitor-location-grid"); }'
), array('class' => 'search_btn'));
?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'location-dialog',
'options' => array(
'title' => 'View Location',
'autoOpen' => false,
'modal' => true,
'width' => 'auto',
'height' => 'auto',
'resizable' => false
),
));
$this->endWidget();
?>
<?php
Yii::app()->clientScript->registerScript('view-location-ajax', "
$('.exb-location').click(function(){
url=$(this).attr('href');
$.ajax({
type: 'post',
url: url,
success: function(result){
$('#location-dialog').html(result).dialog('open');
$('#draggable').draggable();
return false;
}
});
return false;
});
");
?>
View Button工作正常,点击后打开CJuiModel,但是当我在CGridView中添加一个新位置时。 在单击视图按钮时,我的CJuiModel没有打开,页面正在重定向到Url。为什么我的jquery在更新CGridView时失败了。帮助..
答案 0 :(得分:0)
使用JQuery“on”更改ajax调用,而不是直接事件绑定:
此:
...
$('.exb-location').click(function(){
...
更改:
...
$('.exb-location').on('click', '.exb-location', function(){
...
在CGridview刷新后,Html元素被销毁并重新生成。直接JQuery事件仅在DOM加载之前与现有元素一起使用。删除它们后,或稍后添加新元素时,direct events don't work。