_postData : function ()
{
var fieldName = "day";
var day = /*returns an object from the back end business service*/
var value = day.getValue();
if (value)
{
return {
fieldName : value
};
}
}
The problem is, even though fieldName is actually “day”, when the JSON payload gets returned and printed, I am seeing literally:
{
fieldName: "16"
}
So for some reason that variable’s name is being printed, not it’s actual string value. What I want is:
{
day: "16"
}
This is not JSON, it’s Javascript object literals. And when you put a symbol on the left hand side of a property in a Javascript object literal, that is used as the property name, not any string that the variable of that name might evaluate to. In other words,
{fieldName: 16}is exactly equivalent to{"fieldName": 16}Instead of doing this:
You could do something like this:
In the second one, if
fieldNameis a variable containing a string"foo", then the resulting object will look like{foo: 16}