添加Ajax局部刷新demo

pull/202/head
Ricky 4 years ago
parent adcdd046d2
commit cc35627ab1

@ -5,11 +5,15 @@ import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.CxSelect;
import com.ruoyi.common.json.JSONObject;
import com.ruoyi.common.json.JSONObject.JSONArray;
import com.ruoyi.common.utils.StringUtils;
/**
*
@ -217,6 +221,47 @@ public class DemoFormController
return prefix + "/cxselect";
}
/**
*
*/
@GetMapping("/localrefresh")
public String localRefresh(ModelMap mmap)
{
JSONArray list = new JSONArray();
JSONObject item = new JSONObject();
item.put("name", "这条任务数据是由ModelMap传递到页面的点击添加按钮后会将这条数据替换为新数据");
item.put("type", "默认");
item.put("date", "2020.06.10");
list.add(item);
mmap.put("tasks",list);
mmap.put("min",2);
mmap.put("max",10);
return prefix + "/localrefresh";
}
/**
* -
* @param fragment
* @param taskName
*/
@PostMapping("/localrefresh/task")
public String localRefreshTask(String fragment,String taskName,ModelMap mmap)
{
JSONArray list = new JSONArray();
JSONObject item = new JSONObject();
item.put("name", StringUtils.defaultIfBlank(taskName, "通过电话销售过程中了解各盛市的设备仪器使用、采购情况及相关重要追踪人"));
item.put("type", "新增");
item.put("date", "2018.06.10");
list.add(item);
item = new JSONObject();
item.put("name", "提高自己电话营销技巧,灵活专业地与客户进行电话交流");
item.put("type", "新增");
item.put("date", "2018.06.12");
list.add(item);
mmap.put("tasks",list);
return prefix + "/localrefresh::" + fragment;
}
/**
*
*/

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<th:block th:include="include :: header('局部刷新')" />
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-sm-4">
<div class="ibox">
<div class="ibox-content">
<h3>任务列表</h3>
<p class="small">
<i class="fa fa-hand-o-up"></i>
点击刷新按钮刷新数据到列表中
</p>
<div class="input-group">
<input id="task-name" type="text" placeholder="任务名称" class="input input-sm form-control">
<span class="input-group-btn">
<button type="button" class="btn btn-sm btn-white" onclick="refresh()">
<i class="fa fa-refresh"></i>
刷新
</button>
</span>
</div>
<div id="tasklist">
<ul class="sortable-list connectList agile-list" th:fragment="fragment-tasklist">
<li th:if="${tasks != null}" th:each="item : ${tasks}" class="warning-element">
[[${item.name}]]
<div class="agile-detail">
<a href="#" class="pull-right btn btn-xs btn-white">[[${item.type}]]</a>
<i class="fa fa-clock-o"></i>
[[${item.date}]]
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<th:block th:include="include :: footer" />
<script>
function refresh(){
$.ajax({
type: "post",
url: ctx + "demo/form/localrefresh/task",
data: {
"taskName": $("#task-name").val(),
"fragment":'fragment-tasklist'
},
success: function(data) {
$("#tasklist").html(data);
}
});
}
</script>
</body>
</html>

@ -93,6 +93,7 @@
<li><a class="menuItem" th:href="@{/demo/form/duallistbox}">左右互选组件</a></li>
<li><a class="menuItem" th:href="@{/demo/form/autocomplete}">搜索自动补全</a></li>
<li><a class="menuItem" th:href="@{/demo/form/cxselect}">多级联动下拉</a></li>
<li><a class="menuItem" th:href="@{/demo/form/localrefresh}">Ajax局部刷新</a></li>
</ul>
</li>
<li> <a>表格<span class="fa arrow"></span></a>

Loading…
Cancel
Save