我正在使用Scala和Lift获取单页网页应用。我经常用Comet块中的新内容替换部分页面。在其中一种情况下,我收到此错误消息:
找到模板时出错:/template-editContext.html 消息:: 13:31:名字预期,但char' '无法启动名称
当Lift尝试处理错误消息/template-editContext.html
中显示的文件时出现错误,如下所示:
<div id="editContext">
<script>
var contextFields = [];
function parseFieldNames(fieldNames) {
console.log("[parseFieldNames] got: " + fieldNames);
contextFields = fieldNames.split(",");
var x = document.createElement("SELECT");
x.setAttribute("id", "contextFieldSelector");
document.getElementById("addContextFieldSet").appendChild(x);
for(var i = 0; i < contextFields.length; i++) {
var z = document.createElement("option");
z.setAttribute("value", contextFields[i]);
var t = document.createTextNode(contextFields[i]);
z.appendChild(t);
document.getElementById("contextFieldSelector").appendChild(z);
}
}
$(document).ready(function () {
$("#addContextForm").dialog({
autoOpen: false,
modal: true,
buttons: {
"Add field": function() {
var selector = document.getElementById("fieldSelector");
var newField = contextFields[selector.selectedIndex];
console.log("[Add field] adding " + newField);
},
"Create context": function () {
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
},
close: function () {
console.log("[close] closing.");
}
});
$("#addContextButton")
.button()
.click(function (event) {
event.preventDefault();
getFieldList();
$("#addContextForm").dialog("open");
});
$("#modifyContextButton")
.button()
.click(function (event) {
event.preventDefault();
console.log("[modifyContextButton.click] Yo.");
});
$("#deleteContextButton")
.button()
.click(function (event) {
event.preventDefault();
console.log("[deleteContextButton.click] Yo.");
});
});
</script>
<div id="editContextStuff" class="lift:ContextTable.addEditContextCallbacks">
<span id="getFieldList"></span>
<span id="getFieldProperties"></span>
</div>
<div id="addContextForm" title="Add new context">
<form>
<fieldset id="addContextFieldSet">
<label for="name">Name</label>
<input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all"/>
</fieldset>
</form>
</div>
</div>
答案 0 :(得分:4)
Scala xml解析器抱怨您的模板无效xml。您可以尝试设置
LiftRules.htmlProperties.default.set((r: Req) =>
new Html5Properties(r.userAgent))
它将使用HTML5解析器,或者您可以解决xml问题。可能是您的脚本内容未包装在CDATA块中。要使它们有效使用xml:
<script>
<![CDATA[
// your script contents
]]>
</script>
这将向xml解析器指示脚本标记之间的内容是非xml字符数据,不应该被解析。