yii2 ajax 路由,php – Yii2 renderAjax嵌套Listview

我试图通过ajax呈现listview,但它给了我以下错误:

Exception (Invalid Configuration) 'yii\base\InvalidConfigException' with message '

;The "dataProvider" property must be set.

控制器:

public function actionLoadListviewAjax()

{

$dataProvider = // call to a function which returns ArrayDataProvider

return $this->renderAjax('myview', [ 'dataProvider' => $dataProvider ]);

}

视图:

echo ListView::widget([

'dataProvider' => $dataProvider,

'itemView' => 'items',

'options' => ['class' => 'list-view-post'],

'summary' => '',

'emptyText' => '',

]);

$dataProvder:

yii\data\ArrayDataProvider Object

(

[key] =>

[allModels] => Array

(

[0] => Array

(

[RecommendationCategory] =>

[ID] => 37

[GUID] =>

[Title] => test

[WallPostTypeID] => 1

[RecommendationCategoryID] => 0

[CommentsJSON] =>

[TotalComments] =>

[PostedMessage] => test

[FirstName] => test

[LastName] => test

[ProfileImagePath] => Lighthouse.jpg

[AddedOn] => 2015-07-18 15:14:06

[ImagePath] =>

[CommentProfileImagePath] =>

[IsSubscribe] => 1

)

)

[id] =>

[_sort:yii\data\BaseDataProvider:private] =>

[_pagination:yii\data\BaseDataProvider:private] =>

[_keys:yii\data\BaseDataProvider:private] =>

[_models:yii\data\BaseDataProvider:private] =>

[_totalCount:yii\data\BaseDataProvider:private] =>

[_events:yii\base\Component:private] => Array

(

)

[_behaviors:yii\base\Component:private] =>

)

我也尝试了renderPartial,但仍然是同样的错误.任何想法为什么它给出了这个例外?

更新:

在我的itemView文件项中,我有另一个列表视图,它给出了异常.

解决方法:

实际上,列表视图项不必访问已通过窗口小部件发送的外部变量.

但是,如果必须在内部视图文件中使用$dataProvider变量,请尝试使用callable在列表视图中显示项目.

这样的事情:

“`

echo ListView::widget([

'dataProvider' => $dataProvider,

'itemView' => function ($model, $key, $index, $widget) {

return $this->renderAjax('items', [

'dataProvider' => $widget->dataProvider,

]);

},

'options' => ['class' => 'list-view-post'],

'summary' => '',

'emptyText' => '',

]);

“`

更多信息在这里

标签:php,ajax,listview,yii2,yii2-advanced-app

来源: https://codeday.me/bug/20190708/1399684.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值