验证json文件中的小胡子标记值 [英] validate mustache tag value from json file
问题描述
您好,我无法在显示标签之前找到如何验证标签的方法,例如:如果我有JSON文件,可以说以下值:
Hi I havent been able to find how to validate a tag before displaying it, for instance: if I have a JSON file lets says this values:
{ "weeks":
[
{
"monday800": "no",
"monday830": "available",
"tuesday800": "available",
"tuesday830": "no",
"name": "TEST"
}
]
}
我带来这样的价值:
$(function(){
$.get("data.json",function(data){
var template = $("#tpl").html();
var html = Mustache.to_html(template,data);
console.log ();
$("#information").html(html);
});
});
现在我要做的是:
if {{monday830}} == "available" then display {{name}}
Now what I want to do is:
if {{monday830}} == "available" then display {{name}}
推荐答案
在胡须中是不可能的,因为其逻辑较少.改为使用 handlebarsjs .
Its not possible in mustache as its logic less. Use handlebarsjs instead.
如果您仍然想在小胡子上做到这一点,那么:
If you still want to achieve this in mustache then:
您不能使用任何if语句,但是可以检查是否存在任何东西或它的值为true.
You can not use any if statement but you can check if anything exist or its value is true.
在这种情况下,您必须像这样更新json:
if this case you have to update json like:
{ "weeks": [ {
"monday800": "no",
"monday830": "available",
"monday830_available": true, // you have to add another property here
"tuesday800": "available",
"tuesday830": "no",
"name": "TEST"
}
]
}
然后您可以检查
{{#monday830_available}}
..............
{{/monday830_available}}
这篇关于验证json文件中的小胡子标记值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!