我试图通过单击按钮将XML代码还原或生成一个块,并将其设置为我的工作场所。但是它不能正常工作,以某种方式它什么也没显示。我们将不胜感激。 我尝试了以下链接:
2。https://embed.plnkr.co/XIeR0L/
3。https://developers.google.com/blockly/guides/create-custom-blocks/blockly-developer-tools
4。https://developers.google.com/blockly/guides/get-started/web
我要还原的代码:
value = data[5];
alert(value );
Blockly.Xml.appendDomToWorkspace(value ,demoWorkspace);
我还尝试了以下方式:
var xml = Blockly.Xml.textToDom(data[5]);
Blockly.Xml.domToWorkspace(xml, demoWorkspace);
块恢复功能:
function restore() {
$.ajax({
type: "GET",
url: "/save_composition",
content_type : "application/json",
success: function(data) {
value = data[5];
{#console.log(value.replace(/['"]+/g, ''));#}
var result = value.slice(1, -1);
alert(result);
var xml = Blockly.Xml.textToDom(data[5]);
Blockly.Xml.domToWorkspace(xml, demoWorkspace);
},
error: function(xhr, textStatus) {
alert(textStatus);
}});
}
XML的单个响应是:
<xml xmlns="http://www.w3.org/1999/xhtml">
<variables></variables>
<block type="controls_repeat_ext" id="J]k6G0~I).TfgP_;:j=S" x="223" y="65">
<value name="TIMES">
<block type="math_number" id="j{Y2o]x%v(R#1#V*xm)0">
<field name="NUM">10</field>
</block>
</value>
<statement name="DO">
<block type="print_content" id="}$v5G?]mBm(R^8)sri-L">
<value name="to_print">
<block type="text" id="esg1;Q4KV$g;^Ul?BF]p">
<field name="TEXT">test</field>
</block>
</value>
</block>
</statement>
</block>
</xml>