我有一个 Jasonette “应用程序”,它从服务器获取一个简单的数据集并将其显示在列表中。数据是一组人名,每个人名都带有单词“YES”、“NO”、“MAYBE”或 null:
{
"date":"2018-11-07",
"dateFormatted":"Wednesday, November 7th",
"responses":[
{"name":"Jonathan","response":"NO"},
{"name":"Mark","response":"YES"},
{"name":"Stuart","response":"YES"},
{"name":"Jack","response":"MAYBE"},
{"name":"David","response":null}
]
}
以下是应用程序的代码,复制自其中一个特色示例应用程序:
{
"@": "http://web.jasonette.com/items/926",
"title": "OSTT Mincha",
"collection": {
"@": "responses@https://example.com/status.json"
},
"adapter": {
"title": "{{name}}",
"description": "{{response}}"
},
"style": {
"background": "#ffffff",
"header": {
"background": "#ffffff",
"color": "#2a2a2a"
},
"item": {
"title": "#bc9458",
"description": "#001000"
}
}
}
现在,我想对响应行进行颜色编码,“YES”为绿色背景,“NO”为红色,“MAYBE”为黄色。
我尝试修改“Basic ListView Mixin”示例以添加可以添加这些背景的类,如下所示:
{
"$jason": {
"head": {
"title": "Basic ListView Mixin",
"type": "mixin",
"data": {
"collection": {
"@": "$document.collection"
},
"style": {
"@": "$document.style"
},
"styles": {
"YES": {
"background": "#dff0d8"
},
"NO": {
"background": "#f2dede"
},
"MAYBE": {
"background": "#fcf8e3"
}
}
},
"templates": {
"body": {
"header": {
"title": {
"@": "$document.title"
},
"style": {
"background": "{{style.header.background}}",
"color": "{{style.header.color}}"
}
},
"background": "{{style.background}}",
"sections": [
{
"items": {
"{{#each collection}}": {
"type": "horizontal",
"style": {
"padding": "10",
"spacing": "10"
},
"components": [
{
"type": "vertical",
"components": [
{
"type": "label",
"style": {
"font": "HelveticaNeue-Bold",
"size": "12",
"color": "{{$root.style.item.title}}"
},
"class": "{{$document.adapter.description}}",
"text": {
"@": "$document.adapter.title"
}
},
{
"type": "label",
"text": {
"@": "$document.adapter.description"
},
"style": {
"font": "Helvetica",
"size": "11",
"color": "{{$root.style.item.description}}"
},
"class": "{{$document.adapter.description}}"
}
]
}
]
}
}
}
]
}
}
}
}
}
问题是在输出中,我没有看到应用的类。相反,该class
值是{{$document.adapter.description}}
- 原始模板值。
根据我对文档的阅读,应该允许模板值出现在这里。为什么这个模板值没有被替换?