mirror of https://github.com/layui/layui
Merge 358ccdbf56
into 77adc3d196
commit
2eda47faab
|
@ -140,6 +140,50 @@ table.render({
|
|||
该函数非常实用
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
[**ajax**](#options.ajax) <sup>2.12+</sup>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<div class="ws-anchor" id="options.ajax">
|
||||
自定义 ajax 请求,用于发送异步请求。
|
||||
</div>
|
||||
|
||||
```js
|
||||
table.render({
|
||||
// 自定义 ajax 请求
|
||||
// origOptions - 包含了原始的请求参数
|
||||
// type - 执行 ajax 请求的来源,'table' 或 'treeNodes'
|
||||
ajax: function (origOptions, type) {
|
||||
$.ajax({
|
||||
url: origOptions.url,
|
||||
data: origOptions.data,
|
||||
dataType: origOptions.dataType,
|
||||
})
|
||||
.done(function (data) {
|
||||
// 调用原始的 success 回调
|
||||
origOptions.success(data);
|
||||
})
|
||||
.fail(function (xhr, status, error) {
|
||||
// 调用原始的 error 回调
|
||||
origOptions.error(xhr, status, error);
|
||||
})
|
||||
.always(function () {
|
||||
// 调用原始的 complete 回调
|
||||
if (typeof origOptions.complete === "function") {
|
||||
origOptions.complete();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -1196,12 +1196,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports) {
|
|||
|
||||
that.loading(true);
|
||||
|
||||
// 4:代表响应已完成
|
||||
if (that._xhr && that._xhr.readyState !== 4) {
|
||||
that._xhrAbort = true;
|
||||
that._xhr.abort();
|
||||
}
|
||||
that._xhr = $.ajax({
|
||||
var ajaxOptions = {
|
||||
type: options.method || 'get',
|
||||
url: options.url,
|
||||
contentType: options.contentType,
|
||||
|
@ -1249,7 +1244,18 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports) {
|
|||
that.errorView('请求异常,错误提示:'+ msg);
|
||||
typeof options.error === 'function' && options.error(e, msg);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if(options.ajax){
|
||||
options.ajax(ajaxOptions, 'table');
|
||||
}else{
|
||||
// 4:代表响应已完成
|
||||
if (that._xhr && that._xhr.readyState !== 4) {
|
||||
that._xhrAbort = true;
|
||||
that._xhr.abort();
|
||||
}
|
||||
that._xhr = $.ajax(ajaxOptions);
|
||||
}
|
||||
} else if(layui.type(options.data) === 'array'){ //已知数据
|
||||
res = {};
|
||||
var startLimit = curr*options.limit - options.limit;
|
||||
|
|
|
@ -711,7 +711,7 @@ layui.define(['table'], function (exports) {
|
|||
var asyncParseData = asyncSetting.parseData || options.parseData;
|
||||
var asyncResponse = asyncSetting.response || options.response;
|
||||
|
||||
$.ajax({
|
||||
var ajaxOptions = {
|
||||
type: asyncType || 'get',
|
||||
url: asyncUrl,
|
||||
contentType: asyncContentType,
|
||||
|
@ -742,7 +742,14 @@ layui.define(['table'], function (exports) {
|
|||
// 异常处理 todo
|
||||
typeof options.error === 'function' && options.error(e, msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(options.ajax){
|
||||
options.ajax(ajaxOptions, 'treeNodes')
|
||||
}else{
|
||||
$.ajax(ajaxOptions);
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
trExpanded = trData[LAY_HAS_EXPANDED] = true;
|
||||
|
|
Loading…
Reference in New Issue