gpt4 book ai didi

javascript - 数据表中数组变量的粒度操作

转载 作者:行者123 更新时间:2023-11-29 21:11:12 25 4
gpt4 key购买 nike

你可以在这个fiddle中看到我正在寻找一种解决方案,让我可以在相同 Datatables 列中加入几个 JSON 字段。这是我找到的解决方案:

 function ( data, type, full ) {
var a = (full["container-title"]);
var b = (full["volume"]);
var c = (full["issue"]);
var d = (full["page"]);
var x = ([a, b, c, d]);
return $.map( x, function ( d, i ) {
return d;}).join( ', ' );
}

这会输出我想要的值,以逗号分隔。但是,我想在输出之前向 each 变量添加一些 html。比方说,我希望“volume”前面有“Vol.”。但是如果我试试这个

var a = 'Vol.' + (满["音量"]);

该值作为“未定义”传递并且完全不可用。还有其他路线吗?

最佳答案

你的方法确实有效,检查这个 JSFiddle ( https://jsfiddle.net/annoyingmouse/0zdjy1yz/6/ )。您遇到的是无法找到 issue 的相关数据,因为它不在您的数据中,如果您在将其添加到数组之前进行检查,您会大笑:

$('#example').dataTable({
"ajax": {
"url": "https://api.myjson.com/bins/vawiz",
"dataSrc": ""
},
"columns": [{
"data": "",
"defaultContent": null,
"render": function(data, type, full) {
var x = [];
if (full["container-title"]) {
x.push("Title: " + full["container-title"]);
}
if (full["volume"]) {
x.push("Volumns: " + full["volume"]);
}
if (full["issue"]) {
x.push("Issue: " + full["issue"]);
}
if (full["page"]) {
x.push("Page: " + full["page"]);
}
return $.map(x, function(d, i) {
return d;
}).join(', ');
}
}, ],
});

此外,您的脚本包含顺序错误。 :-D

关于javascript - 数据表中数组变量的粒度操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41797212/

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