[英]Check if value of keys is a string with Handlebars
我有一個像這樣的 object:
{
id: 1,
type1: 'Adjective',
type2: 'Noun',
type3: 'Noun',
type4: 'Noun',
type5: 'Plural Noun',
type6: 'Person',
type7: 'Place',
type8: 'Job',
type9: 'Adjective',
type10: 'Adjective',
type11: 'Famous Person',
type12: 'Noun',
type13: 'Noun',
type14: '',
createdAt: 2019-10-11T06:49:38.000Z,
updatedAt: 2019-10-11T06:49:38.000Z
}
有什么方法可以讓我只能使用車把助手獲取值是字符串的鍵?
你可以編寫車把配置助手來檢查這個
module.exports.hbs = exphbs.create({
defaultLayout: 'layout',
helpers: {
//You can Name this anything
checkIfValuesOfJsonAreStrings: function(jsonList, context) {
for (var key in obj) {
if(typeOf obj[key] == "String"){
}else{
return context.inverse(this); // This False
}
}
return context.fn(this)
}
})
現在在編寫 your.hbs 代碼時,您可以包括
{{# checkIfValuesOfJsonAreStrings}}
<div>Yah all the values in JSON are string</div>
{{/checkIfValuesOfJsonAreStrings}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.