Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何格式化用于Mustache HTML呈现的Mustache条件内部字符串?_Javascript_Html_Mustache - Fatal编程技术网

Javascript 如何格式化用于Mustache HTML呈现的Mustache条件内部字符串?

Javascript 如何格式化用于Mustache HTML呈现的Mustache条件内部字符串?,javascript,html,mustache,Javascript,Html,Mustache,我有一个HTML字符串,我想在Mustache中呈现为HTML。但是,该字符串还包含一个Mustache条件。当我在chromedev工具中检查呈现的HTML时,似乎条件实际上是在输入元素中打印出来的,而不是被处理。我认为右括号中的正斜杠可能有问题。在Chrome开发工具中,渲染时会删除/。所以我尝试使用HTML十进制代码。这也不起作用 这是我呈现HTML字符串的地方: <span>{{{response.additionalInfo}}}</span> {{{resp

我有一个HTML字符串,我想在Mustache中呈现为HTML。但是,该字符串还包含一个Mustache条件。当我在chromedev工具中检查呈现的HTML时,似乎条件实际上是在输入元素中打印出来的,而不是被处理。我认为右括号中的正斜杠可能有问题。在Chrome开发工具中,渲染时会删除/。所以我尝试使用HTML十进制代码。这也不起作用

这是我呈现HTML字符串的地方:

<span>{{{response.additionalInfo}}}</span>
{{{response.additionalInfo}}
这就是我要传递给视图的对象。additionalInfo属性具有嵌入的Mustach条件:

var response = {
                templateType: "optIn",
                header: "Opt-In",
                additionalInfo: "<label><input type='checkbox' id='notOptIn' name='isOptIn' {{^response.isOptIn}}checked{{/response.isOptIn}}> YES</label>",
                isOptIn: false,
}
var响应={
模板类型:“optIn”,
标题:“选择加入”,
其他信息:“是”,
异搏定:错,
}

是否可以在Mustache将呈现为HTML的字符串中添加Mustache条件?如果是这样的话,我如何在结尾标记中转义/呢?

我一次调用Mustach就没能让它工作

为了实现它的价值,我在
response.additionalInfo
中转换了模板,并将结果存储在
response.additionalInfo

然后我转换了您提供的模板

使用
isOptIn=false

var响应={
模板类型:“optIn”,
标题:“选择加入”,
其他信息:“是”,
异搏定:错,
}
var template=“{{{response.additionalInfo}}}”;
document.getElementById(“运行”).addEventListener(“单击”,函数(){
response.additionalInfo=Mustache.to_html(response.additionalInfo,窗口);
html=Mustache.to_html(模板、窗口);
document.getElementById(“容器”).innerHTML=html;
});