I'm trying to return a string array. It needs to be in format:
Area: ["0","1","2"]
So this works
Area: ($("#output").find('.pvtUi .pvtRows').text())!=null ?["0"]: ["1","2"]
but not this one
Area: function(){
if ($("#output").find('.pvtRows').text()!=null) {
val=["0"];
return val;}
else return ["1","2"];
}
I've tried all sorts of options. I'm trying to return inclusion list for pivottable.js https://github.com/nicolaskruchten/pivottable/wiki/Parameters any help would be appreciated...
CodePudding user response:
If you need your function to be inline, then you can convert it to an IIFE (immediately invoked function expression).
Eg:
var data = { Area: (function() { return "x" })() };
console.log(data)
In your case this would be:
Area: (function() {
if ($("#output").find('.pvtRows').text() != null) {
val=["0"];
return val;
}
return ["1","2"];
})()
the alternative is to define your function as a function and call it:
function getArea() {
if ($("#output").find('.pvtRows').text() != null) {
...
}
...
Area: getArea()