onde icon indicating copy to clipboard operation
onde copied to clipboard

Removing elements from arrays

Open ghost opened this issue 12 years ago • 2 comments

If you load an array it gets treated as an object:

"expansion_prices": { "0": { "coins": 501, "cash": 10 }, "1": { "coins": 2002, "cash": 15 }, "2": { "coins": 3000, "cash": 20 }, etc

instead of "expansion_prices": [ [ "coins": 501, "cash": 10 ], [ "coins": 2002, "cash": 15 ], [ "coins": 3000, "cash": 20 ], etc.

which causes tons of issues when you are working with sensitive languages such as python for example. Any ideas how to fix this?

ghost avatar Jul 10 '13 13:07 ghost

OK guys I found a solution. I saw the comment: //TODO: Deal with array type in onde.Onde.prototype._sanitizeFieldInfo and I added a quick workaround. Not pretty at all but works. Inside the function, on the first line add

var stringified = JSON.stringify(valueData);

And where the comment is the following lines:

if ( stringified.charAt(0) == '[' ) { fieldInfo.type = 'array'; }

And as far as I can see it works fine. I'll do some more testing and I'll let you know if there are any problems.

ghost avatar Jul 12 '13 08:07 ghost

actually found an issue - cannot use charAt() on an object. So the if condition works as if ( typeof stringified != 'undefined' && stringified.charAt(0) == '[' ) { fieldInfo.type = 'array'; }

ghost avatar Jul 12 '13 09:07 ghost