Yii客户端视图->;分页和AjaxLink/ajaxButton

Yii客户端视图->;分页和AjaxLink/ajaxButton,yii,Yii,我在分页和Ajax表单方面有问题 这是我的控制器的代码: $dataProvider = new CActiveDataProvider('User', array( 'pagination'=>array( 'pageSize'=>10, ), )); $this->render('users',array( 'dataProvider'=>$dataProvider, )); 对于查看->用户

我在分页和Ajax表单方面有问题

这是我的
控制器的代码

$dataProvider = new CActiveDataProvider('User', array(
        'pagination'=>array(
                'pageSize'=>10,
        ),
));

$this->render('users',array(
  'dataProvider'=>$dataProvider,
));  
对于查看->用户:

$this->widget('zii.widgets.CListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_user',
))

对于渲染用户:

echo CHtml::ajaxLink($text, $this->createUrl('admin/deleteuser',array('id'=>$data->iduser)), array('success'=>"js:function(html){ alert('remove') }"), array('confirm'=>_t('Are you sure you want to delete this user?'), 'class'=>'delete-icon','id'=>'x'.$viewid));
如果一个数据库中有15行,它将只显示10行,并将为接下来的5行生成分页(ajaxUpdate=true)。前10行ajaxLink没有问题,因为生成了clientscript,但问题是当我移动到下一页时,ajaxLink不工作,因为它不是通过分页生成的


有什么想法吗?谢谢

我不太确定,但根据过去的经验,我认为问题出在listview小部件本身

如果小部件的所有者是控制器,它将使用renderPartial呈现项目视图。 Renderpartial有一个“processOutput”参数,您可能知道,也可能不知道,对于大多数AJAX魔术来说,该参数需要设置为TRUE(默认为FALSE)


所以,也许您可以尝试派生listview的一个类,并在其中添加“renderItems()”的副本。在这里,您必须更改它,以便它使用正确的参数调用renderPartial。

另一种方法,请选中此项。因此,您的代码将如下所示:

echo CHtml::link($text,
    $this->createUrl('admin/deleteuser',array('id'=>$data->iduser)),
    array(// for htmlOptions
      'onclick'=>' {'.CHtml::ajax( array(
           'beforeSend'=>'js:function(){if(confirm("Are you sure you want to delete?"))return true;else return false;}',
           'success'=>"js:function(html){ alert('removed'); }")).
         'return false;}',// returning false prevents the default navigation to another url on a new page 
    'class'=>'delete-icon',
    'id'=>'x'.$viewid)
);
确认被移动到jquery的
ajax
函数的
beforeSend
回调。如果我们在发送之前从
返回
false
,ajax调用不会发生

另一个建议是,您应该使用
post
变量而不是
get
,如果可以的话,还可以将ajax调用移动到索引视图中的
函数
,只包括来自所有链接的
onclick
事件的函数调用


希望这有帮助。

在小部件Clistview中,我在AjaxUpdate之后添加了

$jsfunction = <<< EOS
js:function(){
    $('.delete-icon').live('click',function(){ 
      if(confirm('Are you sure you want to delete?'))
      {
        deleteUrl = $(this).attr('data-href');
        jQuery.ajax({'success':function(html){ },'url':deleteUrl,'cache':false});
        return false;    
      }
      else
        return false;
    });
  }
EOS;

$this->widget('zii.widgets.CListView', array(
  'dataProvider'=>$dataProvider,
  'id'=>'subscriptionDiv',
  'itemView'=>'_subscription',
  'afterAjaxUpdate'=>$jsfunction,
  'viewData'=>array('is_user'=>$is_user,'all'=>$all),
  'htmlOptions'=>($dataProvider->getData()) ? array('class'=>'table') : array('class'=>'table center'), 
  )
);
$jsfunction=$dataProvider,
'id'=>'subscriptionDiv',
'项目视图'=>''订阅',
'afterAjaxUpdate'=>$jsfunction,
'viewData'=>array('is_user'=>$is_user,'all'=>$all),
'htmlOptions'=>($dataProvider->getData())?数组('class'=>'table'):数组('class'=>'table center'),
)
);
在_中,用户刚刚添加了属性数据href

<?php echo CHtml::ajaxLink($text, $this->createUrl('admin/deletesubscription',array('id'=>$data->idsubscription)), 
            array('success'=>"js:function(html){ $('#tr{$viewid}').remove(); }"), 
            array('confirm'=>_t('Are you sure you want to unsubscribe?'), 
                'class'=>'delete-icon',
                'id'=>'x'.$viewid,
                'data-href'=>$this->createUrl('admin/deletesubscription',array('id'=>$data->idsubscription))                
                )); ?>
试试看

如果这不能解决问题,请尝试在数据提供程序选项中包括记录总数,如下所示:-

'itemCount' => .....,

你必须解释什么是错误的,而不仅仅是输入代码和期望答案。以下是你所面临的问题的描述?对不起,我以为我已经提出了问题。。再次抱歉,当我单击下一页时,由于是ajax,我在控制台(firebug)中看到了结果,我看到ajaxLink jscode已生成,但它仍然无法在父文档上工作。大多数ajax链接需要一些“on document ready”代码绑定到事件等,是的,我只是读了它,我想我没有其他的选择,所以我根据这个想法创建了一些东西。。只需在afterAjaxUpdate上添加代码
'itemCount' => .....,