Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当向下滚动时,yii2在下拉div中显示越来越多的通知_Php_Html_Json_Yii2_Infinite Scroll - Fatal编程技术网

Php 当向下滚动时,yii2在下拉div中显示越来越多的通知

Php 当向下滚动时,yii2在下拉div中显示越来越多的通知,php,html,json,yii2,infinite-scroll,Php,Html,Json,Yii2,Infinite Scroll,我在Select2Kartik小部件中获取通知,一切都很顺利,现在我正试图修改代码以在下拉div中获取数据,但我不知道该怎么做 这是我要在视图中修改的代码 <div class="dropdown-menu animated flipInX"> <div class="dropdown-body niceScroll "> <!-- Start notification list --> <div class="me

我在Select2Kartik小部件中获取通知,一切都很顺利,现在我正试图修改代码以在下拉div中获取数据,但我不知道该怎么做

这是我要在视图中修改的代码

    <div class="dropdown-menu animated flipInX">

    <div class="dropdown-body niceScroll ">

     <!-- Start notification list -->
    <div class="media-list small">
     <a href="#" class="media">
     <?php
     $notificationUrl = Url::to(['site/notification-list']);

    echo Select2::widget([
      'name' => 'state_800',
    'pluginOptions' => [
             'ajax' => [
               'url' => $notificationUrl,
                      'dataType' => 'json',
  'data' => new JsExpression('function(params) { return {q:params.term, page:params.page || 1}; }')
                                                    ],
  'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
   'templateResult' => new JsExpression('function(product) {;return product.text; }'),
     'templateSelection' => new JsExpression('function (subject) { return subject.text; }'),
                       ],
      ]);
                     ?>
                      </a>
        </div> .......

提前感谢。

据我所知,您正在尝试动态更新select2中的选项。如果正确,您可以使用javascript更新select2选项

您的通知来自某些数据库表,您可以发送一个ajax调用来检查是否有未读的通知,并将通知列表返回为JSON,并在运行时更新
Selec2
选项

我可以演示,由于ajax无法在此处实现,因此只需单击按钮,您就可以用ajax调用替换按钮
click
,并将通知传递给
refreshDataSelect2
函数,该函数将更新选项

$('.notifications')。选择2({
占位符:“选择一个选项”,
“宽度”:“100%”
});
$.fn.refreshDataSelect2=函数(数据){
选择2('数据',数据);
//更新选项
var$select=$(此[0]);
var options=data.map(函数(项){
返回“”+item.text+“”;
});
$select.append(options.join(“”)).change();
};
$(“#添加”)。在(“单击”,函数(){
让数据=[{
id:$('.notifications')。子项('option')。长度+1,
文本:“新消息编号”+$('.notifications')。子项('option')。长度
}]
$(“.notifications”).refreshDataSelect2(数据);
});

一些信息
管理信息
私人信息

添加消息
那么您遇到了什么问题?它没有向您显示通知吗?没有,通知在select 2内;其他通知是静态的;因此,我想将它们显示为带有无限滚动条的静态noitifications。我想了解的是,您正在尝试动态更新select2,并使用任何可用的新通知更新选项?或者您正试图按照上图所示对
select2
进行样式化?如果答案对您有效,请选择答案
public function actionNotificationList($page, $q = null, $id = null) {
        $offset = ($page - 1) * 10;

        Yii::$app->response->format = Response::FORMAT_JSON;
        $out = ['results' => ['id' => '', 'text' => '']];
        $query = new Query;
        $query->select(['notification_id as id', new Expression("notification_text AS text")])
                ->from('notification')
                ->offset($offset)
                ->limit(10);

        $command = $query->createCommand();
        $data = $command->queryAll();
        $out['results'] = array_values($data);
        $out['pagination'] = ['more' => !empty($data) ? true : false];
        return $out;
    }