`var RTC_TYPE = [['DS1302','DS1302'],['DS1307','DS1307']];
Blockly.Blocks.RTC_init = {
init: function () {
this.setColour(Blockly.Blocks.sensor.HUE);
this.appendDummyInput("").appendField(Blockly.MIXLY_RTCINIT);
this.appendDummyInput("").setAlign(Blockly.ALIGN_RIGHT).appendField(new Blockly.FieldDropdown(RTC_TYPE), 'RTC_TYPE');
this.appendDummyInput("").setAlign(Blockly.ALIGN_RIGHT).appendField(new Blockly.FieldTextInput('myRTC'), 'RTCName');
this.appendValueInput("SDA")
.appendField("SDA#")
.setCheck(Number);
this.appendValueInput("SCL")
.appendField("SCL#")
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
},
mutationToDom: function() {
var container = document.createElement('mutation');
var type = (this.getFieldValue('RTC_TYPE'));
console.log('=====get WHAT?=====');
console.log(type);
container.setAttribute('rtc_type', type);
return container;
},
domToMutation: function(xmlElement) {
var RTC_TYPE = xmlElement.getAttribute('rtc_type');
this.updateShape_(RTC_TYPE);
},
updateShape_: function(RTC_TYPE) {
// Add or remove a Value Input.
if (RTC_TYPE == 'DS1302') {
this.appendValueInput("RST")
.appendField('RST#')
.setCheck(Number);
} else if (RTC_TYPE == 'DS1307'){
/*if (this.childBlocks_.length > 0) {
for (var i = 0; i < this.childBlocks_.length; i++) {
if (this.childBlocks_[i].type == 'Number') {
this.childBlocks_[i].unplug();
break;
}
}
}*/
this.removeInput('RST');
}
}
};`
but this block didn't changed when I selected different content in dropdown menu.
Can you help me?
thanks
在 2017年11月14日星期二 UTC+8上午1:02:34,Andrew n marshall写道: