简体   繁体   English

Jscroll加载相同的内容

[英]Jscroll loading same content

I am using jscroll to autoscroll content. 我正在使用jscroll自动滚动内容。 Script section is given below 脚本部分如下

  <script type="text/javascript">
        $('ul.pagination').hide();
        $(function() {
            $('.infinite-scroll').jscroll({
                refresh: true
                autoTrigger: true,
                loadingHtml: '<img class="center-block" src="/images/loading.gif" alt="Loading..." />',
                padding: 0,
                nextSelector: '.pagination li.active + li a',
                contentSelector: 'div.infinite-scroll',
                callback: function() {
                    $('ul.pagination').remove();
                }
            });
        });
    </script>

Now my blade.php 现在我的blade.php

<div class="infinite-scroll">    
   @foreach($questions as $q)
      <div class="panel panel-default pan">
        <div class="panel-heading pin" role="tab" id="heading{{$q->id}}">
           <h4 class="panel-title">
           <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse{{$q->id}}" aria-expanded="true" aria-controls="collapse{{$q->id}}">
                                        {{ substr($q->question,0,55)}}....                                </a>
            </h4>
          </div>
        <div id="collapse{{$q->id}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading{{$q->id}}">
           <div class="panel-body">
               {{$q->question}}
                <div class="comments-holder" id="ch{{$q->id}}">                                        
                   @foreach($q->comment as $c)
                      <div class="comment-item">
                          <div class="avatar">
                              <i class="fa fa-user"></i>
                          </div>
                          <div class="comments">
                              <h6>{{$c->username}}</h6>
                              <p>{{$c->comment}}</p>
                         </div>
                       </div>
                  @endforeach
               <div class="comment-form">
              @if(Auth::user())
                <form id="{{$q->id}}" class="commentform">
                  {{csrf_field()}}
                  <textarea name ="comment" class="comm_clear" id="comment{{$q->id}}" required placeholder="Type your comments" rows="3"></textarea>
                  <input type="hidden" name="question_id" id="question_id{{$q->id}}" value="{{$q->id}}"/>
                  <button type="button" class="discussion" onclick="submitq(this)">Submit</button>
                   </form>       
                   @endif 
                  </div>
               </div>
             </div>
          </div>
         </div>
        <?php $i=1;?>
        @endforeach
        {{ $questions->links() }}
      </div>

My controller code is 我的控制器代码是

  $questions = Question::where('lesson_id', '=', $lesson->id)->paginate(4);
        foreach ($questions as $q) {
            $q->comment = Comment::join('users', 'users.id', '=', 'comments.user_id')
                ->select('users.name as username', 'comments.comment')
                ->where('question_id', '=', $q->id
                )->get();
        }

My problem is same data is loading infinitely.I have attached screenshot.How to stop load data if not available.The same content is repeating when i scroll down.I am stuck here. 我的问题是相同的数据正在无限加载。我已经附上了屏幕截图。如何在不可用的情况下停止加载数据。当我向下滚动时重复相同的内容。 在此处输入图片说明

Your code seems complex to me, it may take time to understand it to anyone who is willing to help, and I think that's why you are not getting any responses. 对于我来说,您的代码似乎很复杂,对于愿意提供帮助的任何人来说,可能需要花费一些时间来理解它,而我认为这就是为什么您没有得到任何答复的原因。

I recommend to test jscroll first on your system on something small, try to minimize the code in order to separate Laravel and jscroll 我建议先在您的系统上测试小型的jscroll,尝试最小化代码以分离Laravel和jscroll

Let's say get simply all columns of a table and display them in a small view with pagination of let's say 5 rows and implement jscroll on it. 假设仅获取表的所有列,并在一个小视图中显示它们,例如分5行,并在其上实现jscroll。

Check if it works, if it does, then gradually insert your actual application logic into it and keep testing. 检查它是否有效,如果可以,则逐渐将实际的应用程序逻辑插入其中并继续进行测试。

In my opinion this is good way to identify the bug by separating it from other parts of your application 我认为这是通过将其与应用程序的其他部分分开来识别错误的好方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM