我是Mustache的新手,我遇到了一些问题
我的JSON如下所示
var Views = {
"$id": "11",
"name": "Life",
"id": "Life_932",
"createdDate": "12/01/2017",
"updatedDate": "12/01/2017",
"defaultView": false,
"background": "#1395C6",
"share": {
"accessType": 82007,
"specificUsers": [
{
"users": "872",
"permission": 1
}
]
},
"shared": true,
"dashletUserId": 932,
"Username": "ZAM"
}
var temp = '<div class="menuContainer">' +
'<div class="createCopytxt {{#shared}}disableClass{{/shared}}"><span class="createCopy"></span>Create Copy</div>' +
'<div class="renameDashboardtxt {{#shared}}disableClass{{/shared}}"><span class="renameDashboard"></span>Rename</div>' +
'<div class="deleteDashboardtxt {{#shared}}disableClass{{/shared}}"><span class="deleteDashboard"></span>Delete</div>' +
'<div class="defaultDashboardtxt"><span class="defaultDashboard"></span>Set as Default</div>' +
'</div>' +
var out = Mustache.render(template, Views);
我想根据用户的权限禁用classname createCopytxt,renameDashboardtxt和deleteDashboardtxt。目前它基于共享值。
提前感谢您的时间。
答案 0 :(得分:0)
如果属性“共享”是真实的,则只包括该类。
<div class="{{#shared}}renameDashboardtxt{{/shared}}"><span class="renameDashboard"></span>Rename</div>
如果你想用disableClass实际替换createCopytxt / renameDashboardtxt / deleteDashboardtxt,你可以这样做:
<div class="{{#shared}}renameDashboardtxt{{/shared}}{{^shared}}disableClass{{/shared}}"><span class="renameDashboard"></span>Rename</div>
查看Mustache文档,特别是“倒置”部分:Get coordinates from the contour in matplotlib?