如何使用Grunt将多个JSON文件加载到Jade模板中? [英] How to load multiple JSON files into Jade templates using Grunt?

查看:152
本文介绍了如何使用Grunt将多个JSON文件加载到Jade模板中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用Grunt成功加载一个JSON文件作为我的Jade模板的数据源,类似于这个解决方案

现在我需要加载一组JSON文件我的项目中的不同文件夹,以便可以从Jade模板访问它们中的所有数据。如何在Grunt任务的上下文中更好地完成它?

解决方案

您可以使用此方法载入尽可能多的json文件:

  // Jade => HTML 
gruntConfig.jade = {
编译:{
options:{
data:{
object:grunt.file.readJSON('JSON_FILE.json'),
object1:grunt.file.readJSON('JSON_FILE_1.json'),
object2:grunt.file.readJSON('JSON_FILE_2.json'),

}
},
}
};

然后在Jade模板中,您只需引用该对象。 IE:

 脚本(src = object.baseURL +js / vendor / jquery.js)
脚本src = object.baseURL +js / vendor / requireQuery.js)
script(data-main =js / main,src = object.baseURL +js / vendor / require.js)

我知道这个问题有点晚了,但对于任何人来说, ,这是使用Grunt.js将多个JSON文件加载到Jade模板的答案。


I can successfully load one JSON file as a data source for my Jade templates using Grunt, similar to this solution.

Now I need to load a set of JSON files from different folders inside my project so that all the data from them is accessible from Jade templates. How to do it better in context of Grunt tasks?

解决方案

You can load as many json files as you like with this method:

    // Jade => HTML
gruntConfig.jade = {
    compile: {
        options: {
            data: {
                object: grunt.file.readJSON('JSON_FILE.json'),
                object1: grunt.file.readJSON('JSON_FILE_1.json'),
                object2: grunt.file.readJSON('JSON_FILE_2.json'),

            }
        },
    }
};

And then in the Jade template you simply need to reference the object. IE:

    script(src= object.baseURL + "js/vendor/jquery.js")
    script(src= object.baseURL + "js/vendor/elementQuery.js")
    script(data-main="js/main", src= object.baseURL + "js/vendor/require.js")

I know this is being answered a bit late but for anyone who comes across this from a google search as I have, this is the answer to loading multiple JSON files into a Jade template using Grunt.js.

这篇关于如何使用Grunt将多个JSON文件加载到Jade模板中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆