数据库中数组变量的粒度操纵 [英] Granular manipulation of array variables in Datatables

查看:77
本文介绍了数据库中数组变量的粒度操纵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以在此小提琴中看到我正在寻找一个解决方案,让我在相同的 Datatables列中加入了两个JSON字段。这是我找到的解决方案:

You can see in this fiddle that I'm looking for a solution that lets me join a couple of JSON fields in the same Datatables column. This is the solution I found:

 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( ', ' );
    }

这将输出我想要的值,用逗号分隔。但是,我想在输出之前添加一些html到每个变量。比方说,我想要卷前面加上卷。但是如果我尝试这个

This outputs the values I want, separated by commas. However, I would like to add some html to each variable before the output. Say, for instance, I want "volume" to be preceded by "Vol.". But if I try this

var a ='Vol。'+(full [volume]);

该值被传递为未定义,完全无法使用。任何其他路线?

the value is passed as "undefined" and completely unusable. Any other route?

推荐答案

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

Your approach does work, check this JSFiddle (https://jsfiddle.net/annoyingmouse/0zdjy1yz/6/). What you were running into was not being able to find the relevant data for issue as it's not in your data, if you do a check before adding it to the array you're laughing:

$('#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

Also, your script includes were in the wrong order. :-D

这篇关于数据库中数组变量的粒度操纵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆