嗨我想檢查HB中的字符串響應。我試過這個:檢查句柄狀態
{{#if status=='false'}}
{{console.log("hi");}}
{{else}}
{{console.log("no");}}
{{#endif}}
我該如何檢查回覆簡單?如果它是真的,我想顯示一條消息,如果它是錯誤的,則顯示另一條消息。
嗨我想檢查HB中的字符串響應。我試過這個:檢查句柄狀態
{{#if status=='false'}}
{{console.log("hi");}}
{{else}}
{{console.log("no");}}
{{#endif}}
我該如何檢查回覆簡單?如果它是真的,我想顯示一條消息,如果它是錯誤的,則顯示另一條消息。
把手設計非常簡單,並且沒有開箱即用的功能。你應該通過狀態爲一個布爾而不是一個字符串,那麼就使用if語句:
{{#if status}}
{{console.log("hi");}}
{{else}}
{{console.log("no");}}
{{#endif}}
你也可以寫一個輔助函數:
Handlebars.registerHelper('ifEq', function(a, b, options) {
if (a == b) return options.fn(this)
else return options.inverse(this)
});
那麼你的車把變成:
{{#ifEq status 'true'}}
Hello
{{else}}
No
{{/ifEq}}
我有這個錯誤:「」缺少幫手:「ifEq \」「, 」name「:」錯誤「, 」stack「:」錯誤:缺少幫手: – Hateres1990
您需要註冊幫助功能如上'Handlebars.registerHelper' – Bill
我剛剛複製了您的確切代碼。 – Hateres1990
可能回答在http://stackoverflow.com/questions/17499742/how-do-i-add-console-log-javascript-logic-inside-of-a-handlebars-template請檢查。 –