gpt4 book ai didi

jsgrid - loadData 只是行不通

转载 作者:行者123 更新时间:2023-12-01 23:15:37 25 4
gpt4 key购买 nike

下面是我的完整代码。没有错误,并且显示了 Directory is empty

<script>
$(document).ready(function() {
$("#table").jsGrid({
width: "100%",
height: "auto",
paging: false,
autoload: false,
noDataContent: "Directory is empty",

controller: {
loadData: function(filter) {
var data = {
data: [{
nickname: "test",
email: "t@gmail.com"
}]
};
console.log(data);
return data;
}
},
fields: [{
name: "nickname",
type: "text",
width: 80,
title: "Name"
}, {
name: "email",
type: "text",
width: 100,
title: "Email Address",
readOnly: false
}]
});
});
</script>

控制台输出如下。格式有什么不正确的地方吗?

enter image description here

有没有办法启用更多诊断,例如打印出它实际接收到的数据以便进行故障排除?

最佳答案

你需要设置autoload:true

自动加载(默认为 false)

一个 bool 值,指定是否在呈现网格时调用 controller.loadData

而且你还需要在 loadData() 中返回 data.data mehtod 因为你在数据中有数组。

代码片段

controller: {
loadData: function(filter) {

var data = {
data: [{
nickname: "test",
email: "t@gmail.com"
}]
};
return data.data; //As per your data array is like this console.log(data.data) so you need to send like this data.data
}
},

演示

$(document).ready(function() {

$("#table").jsGrid({
width: "100%",
height: "auto",
paging: false,

//for loadData method Need to set auto load true
autoload: true,

noDataContent: "Directory is empty",

controller: {
loadData: function(filter) {

alert('Table load data method fire because we have set config autoload:true')
var data = {
data: [{
nickname: "test",
email: "t@gmail.com"
}]
};
return data.data;//As per your data array is like this console.log(data.data) so you need to send like this data.data
}
},

fields: [{
name: "nickname",
type: "text",
width: 80,
title: "Name"
}, {
name: "email",
type: "text",
width: 100,
title: "Email Address",
readOnly: false
}]
});

$("#table1").jsGrid({
width: "100%",
height: "auto",
paging: false,

//for loadData method will not work with auto load false
autoload: false,

noDataContent: "Directory is empty",

controller: {
loadData: function(filter) {
alert('Table 1 load data method not fire')
return []
}
},

fields: [{
name: "nickname",
type: "text",
width: 80,
title: "Name"
}, {
name: "email",
type: "text",
width: 100,
title: "Email Address",
readOnly: false
}]
});
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css" />
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>


<div id="table"></div>
<br>
<br>
<br>
<div id="table1"></div>

关于jsgrid - loadData 只是行不通,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51165497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com