How to return JSON array instead of text for specific column
Closed this issue · 7 comments
I want to return a JSON array from an extractor like this:
`
10 : function(cellIndex , $cell){
var prlArray = [];
$cell.find('select option').each(function(){
//alert(this.value);
prlArray.push(this.value);
});
return JSON.parse(prlArray.toString());
}
`
This extractor is causing error in because of "return JSON.parse(prlArray.toString());"
thanks in advance
does this not work?
function(cellIndex , $cell){
var prlArray = [];
$cell.find('select option').each(function(){
//alert(this.value);
prlArray.push(this.value);
});
return prlArray;
}
It does, but it is concatenated to the rest data as String not array like this :
{ parallelActions: "8,2,3"}
but what i need is to be like this:
{parallelActions : [8,2,3]}
Just looked at the code. It will always convert whatever you give it into a string. As far as I know there is no way around this in the current version.
You could process this.value
before pushing it into the prlArray
.
Maybe you can try using this simple jQuery plugin called nVal()
... use $(this).nVal()
and it will return an array of numbers.
@Mottie I think the problem is that anything returned from the extractor function is automatically converted to a string by the $.trim
function: https://github.com/lightswitch05/table-to-json/blob/master/src/jquery.tabletojson.js#L55
@SamehMahmoud I @lightswitch05 I submitted a PR #37 which should be able to fix this issue.
released in 0.12.0