【问题标题】:Updating partial JS Api OcoberCMS更新部分 JS Api OcoberCMS
【发布时间】:2020-12-08 10:33:36
【问题描述】:

我正在尝试使用 AJAX 对表格进行排序

ScheduleC.php

        public function onSort() {

            $groupId = (int)post('groupid');
            $professorId = (int)post('professorid');

            $schedules = Schedule::orderBy('date', 'desc')->get();

            if (($groupId) && ($groupId!='-1')) {
                $this->sortByGroup($groupId, $schedules);
            }

            if (($professorId) && ($professorId!='-1')) {
                $this->sortByProfessor($professorId, $schedules);
            }

            $this->schedule = $this->page['schedule'] = $schedules;
            
            return  $this->page['schedule'];
        }

default.php

<div id="schedule-table-container">
    {% partial '@schedule-table' %}
</div>

schedule.js

$(document).ready(function() {
    $('#sortschedule').submit(function(event) {
        event.preventDefault();
        $(this).request('onSort', {         
        update: {'schedulec::schedule-table': '#schedule-table-container'},
        success: function(data) {
            console.log(data);
            this.success(data);
        }
        });
    });
});

函数返回正确的数据,但部分没有更新。

最有趣的是,类似的代码正在我的另一个项目中工作。请帮忙。

【问题讨论】:

  • “请帮忙。” - 什么?到目前为止,您完全没有在此处包含 任何 形式的问题描述!请阅读How to Ask
  • @CBroe 函数返回正确的数据,但部分没有更新

标签: javascript php ajax laravel octobercms


【解决方案1】:

这里真正的问题是因为您调用了成功选项。 Read more here。因此,通过不从服务器返回任何内容的解决方案不会执行停止ajaxUpdatesuccess() 选项。

"Success() | 请求成功时执行的回调函数。如果提供此选项,它将覆盖默认框架的功能:元素不会更新,beforeUpdate 事件不会触发,@987654325 @ 和 ajaxUpdateComplete 事件不会被触发。事件处理程序获取 3 个参数:从服务器接收的数据对象、文本状态字符串和 jqXHR 对象。但是,您仍然可以调用默认框架功能调用 this.success(。 ..) 在你的函数中。”

【讨论】:

    【解决方案2】:

    我通过删除处理程序中的 return 解决了这个问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-27
      • 1970-01-01
      • 2013-07-31
      • 2017-12-09
      • 2019-07-13
      • 2019-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多