Hi,
I'm using Blockly in a project where non-IT people need to build small code snippets and Blockly seems to be the right tool to support them.
To get access to the data I'd like them to drag and drop objects from a tree into Blockly so they can access the data from those objects in their code.
A custom block gets created with the corrosponding data as JSON insinde the <data> element and I can access everything I need at "compile time" (during code generation).
For some of those objects selections can be made, so naturally I'd like to do that with a FieldDropdown.
But when instantiating blocks this.data is undefined and I am unable to generate a dropdown from the <data> element.
Is there another way to archive this?
init: function() {
this.setColour(type.color);
var label = this.appendDummyInput();
label.appendField(type.type + '_node');
label.appendField(new Blockly.Field(), 'nodename');
label.appendField(new Blockly.FieldDropdown(this.options), 'nodevalue');
this.setOutput(true, type.type);
},
getNode: function() {
return JSON.parse(this.data);
},
options: function() {
var opts = [];
var node = JSON.parse(this.data);
for (var port in node.ports)
{
}
return opts;
}
JSON.parse works fine in getNode, but fails in options.