Javascript 在KendoUI Jquery中使用空对象筛选列
在下面的专栏中,我已经管理了如何控制模板中的空值,以及如何进行排序:Javascript 在KendoUI Jquery中使用空对象筛选列,javascript,jquery,kendo-ui,Javascript,Jquery,Kendo Ui,在下面的专栏中,我已经管理了如何控制模板中的空值,以及如何进行排序: { field: "SucursalDetails.Nombre", title: "Sucursal", width: 40, template: "# if (SucursalDetails == null) { #" + "<span data-content=' '>-</span>" + "# } else { #" + "<sp
{
field: "SucursalDetails.Nombre", title: "Sucursal", width: 40,
template: "# if (SucursalDetails == null) { #" +
"<span data-content=' '>-</span>" +
"# } else { #" +
"<span'> #: SucursalDetails.Nombre #</span>" +
"# } #",
sortable: {
compare: function (a, b, descending) {
if (a.SucursalDetails == null && b.SucursalDetails == null) {
return 0;
}
else {
if (a.SucursalDetails == null || b.SucursalDetails == null) {
return descending ? 1 : -1;
}
else {
if (descending) {
return b.Id - a.Id;
} else {
return a.Id - b.Id;
}
}
}
}
{
字段:“SucursalDetails.Nombre”,标题:“Sucursal”,宽度:40,
模板:“#如果(SucursalDetails==null){#”+
"-" +
“#}否则{#”+
过滤时,javascript控制台显示“TypeError:d.SucursDetails为空”
不正确,因为函数中未使用d.SucursalDetails,但我知道问题出在哪里
你可以试试这个
{
field: "SucursalDetails.Nombre", title: "Sucursal", width: 40,
template: "# if (!SucursalDetails) { #" +
"<span data-content=' '>-</span>" +
"# } else { #" +
"<span'> #: SucursalDetails.Nombre #</span>" +
"# } #",
sortable: {
compare: function (a, b, descending) {
if (!a.SucursalDetails && !b.SucursalDetails) {
return 0;
}
else {
if (!a.SucursalDetails || !b.SucursalDetails) {
return descending ? 1 : -1;
}
else {
if (descending) {
return b.Id - a.Id;
} else {
return a.Id - b.Id;
}
}
}
}
{
字段:“SucursalDetails.Nombre”,标题:“Sucursal”,宽度:40,
模板:“#如果(!SucursalDetails){#”+
"-" +
“#}否则{#”+
“在我的工作中终于解决了它
我们将以下内容添加到架构中:
parse: function(response) {
for (var i = 0; i < response.d.results.length; i++) {
//for each optional entity in your OData expand, add an entry here
if (response.d.results[i]['SucursalDetails'] == null)
{
response.d.results[i]['SucursalDetails'] = {
Nombre: '-'
};
}
}
return response;
}
parse:函数(响应){
对于(var i=0;i
在这段代码中,模板和sortable的使用变得毫无用处,因为没有对象是空的