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

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

问题描述

昨天我被介绍给了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.

接下来,我寄我会认为是相关code:

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 事件具有更多的功能,以prevent在关闭对话框。

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.

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

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