简体   繁体   English

在jquery datatable render函数中获取对象变量名称

[英]get object variable name in jquery datatable render function

I have a dto returned from service, I would like to insert the values in the datatable. 我有一个从服务返回的dto,我想在数据表中插入值。 for custom rendering of values i have used "render" function like below. 对于值的自定义呈现,我使用了如下的“呈现”功能。

"columns": [
             { "render": render },
             { "data": "description" },
           ]

The function is 该功能是

function render(data, type, row){       
    return "some data...";
}

For the above code i would like to check conditions with the object's variable name as 对于上面的代码,我想检查对象的变量名称为

obj:{name:"harris",age:"20"}

while rendering the function i would like to check whether it is name or age, if the data is name it will return some value. 在渲染函数时,我想检查它是名字还是年龄,如果数据是名字,它将返回一些值。 If it is an age it will return some other value. 如果是年龄,它将返回其他值。

you can do this way 你可以这样

if(row.name != null){
    // code for name 
}else if(row.age != null){
    // code for age 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM