afterAjaxUpdate callbackFunction参数CListView显示未定义 [英] afterAjaxUpdate callbackfunction CListView shows undefined

查看:120
本文介绍了afterAjaxUpdate callbackFunction参数CListView显示未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调用其在另一个js文件通过文件名的afterAjaxUpdate放慢参数中定义的函数,但我在控制台得到错误功能没有定义

i am trying to call a function which is defined in another js file by afterAjaxUpdate paramter of the file name but i got error in console that function is not defined

<?php 
$dataProvider=new CActiveDataProvider('profiles',array('pagination'=>array('pageSize'=>3))); ?>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_profilesview',
'template'=>'{sorter}<br />{pager}{items}{pager}',
    'enableSorting' => true,
    'sortableAttributes'=>array(
     'name'=>'By firstName',
     'location'=>'By city',
     'age'=>'By age',
     'likes'=>'By likes'
     ),
     'afterAjaxUpdate'=>'readcookie()',
));
 ?>

我的js函数是

my js function is

$(document).ready(function(){
   function readcookie()
   {
       alert("hi");
   }
});

我可以在该功能的文件中定义包含所有包含被Yii默认情况下,js文件后,我的消息来源看 当我注册在我的布局,我的剧本就dosent找到$因为jQuery不包括当我包括jQuery的它被包含了两次,导致触发我的事件 我也试图通过设置

i can see in my source that function defined in the file is included after all the js files that are included by yii default when i register my script in my layout it dosent find $ because jquery not included when i include jquery it gets included twice which leads to trigger my event i also tried to by setting

的RenderPartial(Mybelowview',空,假,真)

renderPartial('Mybelowview',null,false,true)

这又导致我的js文件,包括多次和我的事件GOTS触发多个时间。

which leads again my js file to include multiple times and my event gots trigger multiple time.

这是非常混乱,请帮助得到了它 感谢所有为如此大手笔

This is very confusing please help to get out of it Thanks all for being so generous

推荐答案

问题是,在 $(文件)。就绪功能(); 超出范围它,这就是为什么你的未定义的。所以,你可以只具备:

The problem is that functions inside $(document).ready(); are out of scope outside of it, and that's why you get undefined. So you can either just have:

// $(document).ready(function(){
   function readcookie()
   {
       alert("hi");
   }
// });
// omit document.ready to make function available in the global scope

或定义函数窗口对象,使其全球的:

or define the function on the window object to make it global:

$(document).ready(function(){
   window.readcookie=function ()
   {
       alert("hi");
   };
});

最后定义属性afterAjaxUpdate为:

'afterAjaxUpdate'=>'readcookie'
// if it is readcookie() it becomes a function call instead

这篇关于afterAjaxUpdate callbackFunction参数CListView显示未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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