Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jQuery中渲染把手辅助对象_Jquery_Node.js_Express_Handlebars.js - Fatal编程技术网

在jQuery中渲染把手辅助对象

在jQuery中渲染把手辅助对象,jquery,node.js,express,handlebars.js,Jquery,Node.js,Express,Handlebars.js,我正试图使用jquery将一个代码片段附加到我的主模板(Handlebar)中 var appendToDiv = function(data){ return ` <div class='some class'> {{{formatDate ${data.created_at} 'MMM DD YYYY'}}} </div> ` } 这里的问题是,没有编译handlebar帮助程序。希望问题足够清楚。任何

我正试图使用jquery将一个代码片段附加到我的主模板(Handlebar)中

var appendToDiv = function(data){
   return `
       <div class='some class'>
          {{{formatDate ${data.created_at} 'MMM DD YYYY'}}}
        </div>
    `
}

这里的问题是,没有编译handlebar帮助程序。希望问题足够清楚。任何帮助都将不胜感激。提前谢谢

这就是我最终的做法

在主模板文件
index.handlebar
中,我创建了一个类似这样的部分

<div id='content'></div>

<script id="template" type="text/x-handlebars-template">
    <div class="someclass">
       {{formatDate mydate 'MM DD YYYY'}}
    </div>
</script>

希望其他人觉得这很有用。

您的意思是该函数以文本形式返回mustach吗?在附加html文本之前,您肯定需要调用模板引擎。您是在前端使用手柄还是在后端使用手柄frontend@Artem,函数应该返回一个字符串,我可以将它附加到模板中的div中<代码>2018年5月2日@lacasera是的,我理解。但它叫车把圣殿骑士吗?
<div id='content'></div>

<script id="template" type="text/x-handlebars-template">
    <div class="someclass">
       {{formatDate mydate 'MM DD YYYY'}}
    </div>
</script>
var template = document.getElementById('template')
var view = Handlebars.compile(template)
var templateToDisplay = view(mydate)
$('#content').append(templateToDisplay)