我正在尝试通过单击按钮恢复或生成带有 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>