当由AJAX调用触发添加新记录时,如何更新Yii的CListView? [英] How can I update Yii's CListView when a new record was added triggered by an AJAX call?

查看:42
本文介绍了当由AJAX调用触发添加新记录时,如何更新Yii的CListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天,我被介绍给CListView,并且可以设法以我想要的格式显示我想要的有关记录的所有信息.我有一个创建"按钮(添加一个新的联系人),它会打开一个带有相应字段的模式弹出窗口.关闭此窗口后,我返回到CListView,这是我的问题:我一直在尝试更新CListView(显然没有任何运气).

Yesterday I was introduced to the CListView and could manage to display all the information i want about my records, and in the format i want. I have a 'create' button (add a new contact), which opens a modal pop up window with the corresponding fields. When this window is closed, i return to the CListView, and here is my issue: i've been trying to update the CListView (without any luck, clearly).

我相信通过以下调用来更新clistview应该很容易:$ .fn.yiiListView.update(' CListViews的ID '),但是我找不到应该触发的正确事件这个电话.

I believe it should be easy to update the clistview with this call: $.fn.yiiListView.update('CListViews's ID'), but i can't find the proper event that should trigger this call.

接下来,我发布我认为是相关代码的内容:

Next, i post what i would think is the relevant code:

按钮

echo CHtml::ajaxButton ("Create",
                          CController::createUrl('/contacts/create'),
                          array('onclick'=>'
                                    $("#createContact").dialog("open");
                                    return false;',
                                    'update'=>'#createContact'), 
                          array('id'=>'showCreateContactDialog'));?>

CListView

$this->widget('zii.widgets.CListView', array(
    'dataProvider'=>new CArrayDataProvider($model->contacts, array('pagination'=>array('pageSize'=>5,),)),
    'itemView'=>'_view',
    'emptyText'=>'empty',
    'template'=>"{items}\n{pager}", 
    'pagerCssClass'=>'page-number',
    'id'=>'ajaxListView',
));?>

非常欢迎任何帮助!!希望这最终能对某人有所帮助.

Any help is more than welcome!! Hope this helps someone eventually as well.

推荐答案

如果我正确理解,您的问题是找到触发 CListView 更新的方法(您提供的JS更新代码片段应该可以正常工作).

If I understand correctly, your problem is finding what to trigger the CListView update with (the JS update snippet you provide should work fine).

您正在寻找 jQuery对话框事件关闭;对话框关闭后,它将被触发.另外,还有一个 beforeClose 事件具有附加功能,可以防止对话框关闭.

Probably the jQuery dialog event close is what you are looking for; it will get triggered after the dialog has been closed. Alternatively, there is also a beforeClose event that has the additional capability to prevent the dialog from closing.

这篇关于当由AJAX调用触发添加新记录时,如何更新Yii的CListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆