Javascript 车把预编译类型错误

Javascript 车把预编译类型错误,javascript,handlebars.js,Javascript,Handlebars.js,我的手柄预编译模板中出现typeError 环顾stackoverflow之后,问题似乎与任务编译器和Handlebar版本之间的兼容性问题有关 这是我的车把版本: $handlebar-v 2.0.0 $handlebars postlist.hbs | grep“编译器” },“编译器”:[6,”>=2.0.0-beta.1”] :handlebar.compiler_版本的浏览器输出为6 我猜这可能是我的问题,但不确定如何升级我的编译器以放弃测试版。(?)[这应该不是问题,因为两者都匹配]

我的手柄预编译模板中出现typeError

环顾stackoverflow之后,问题似乎与任务编译器和Handlebar版本之间的兼容性问题有关

这是我的车把版本:

$handlebar-v 2.0.0

$handlebars postlist.hbs | grep“编译器” },“编译器”:[6,”>=2.0.0-beta.1”]

:handlebar.compiler_版本的浏览器输出为6

我猜这可能是我的问题,但不确定如何升级我的编译器以放弃测试版。(?)[这应该不是问题,因为两者都匹配]

“我的grunt任务”不会引发任何错误,文件已创建:

$grunt车把:编译

运行“handlebar:compile”(handlebar)任务

已创建1个文件

完成,没有错误

这是我的一行js:var template=handlebar.templates['postlist']

这是我在console.log中遇到的错误 未捕获的TypeError:无法读取未定义的属性“postlist”

请帮忙

这是我的grunt文件:

(function(){
  'use strict';
  module.exports = function(grunt) {

    // Global Vars
    var _globalConfig = {
      lessDir: '_less/',
      cssDir: 'css/',
      jsDir: 'js/',
      iconsDir: 'assets/icoMoon/SVG/',
      templateDir: 'temptpl/'
    };

    // Project configuration.
    grunt.initConfig({
      // Global Vars
      _globalConfig: _globalConfig,
      pkg: grunt.file.readJSON('package.json'),  

      // File Includes, https://github.com/vanetix/grunt-includes
      // TODO: set this up.
      includes: {
        files: {
          src: ['path/to/foo.html', 'path/to/bar.html'], // Source files
          dest: 'tmp', // Destination directory
          flatten: true,
          cwd: '.',
          options: {
            silent: true,
            banner: '<!-- Include File Location: <% includes.files.dest %> -->'
          }
        }
      },
      // Suit CSS Preprocessor
      suitcss: {
        options: {
          // Task-specific options go here.
          conform: false
        },
        your_target: {
          files: {
            '<%= _globalConfig.cssDir %><%= pkg.name %>-suit.dev.css': ['<%= _globalConfig.cssDir %>lib/site.css','<%= _globalConfig.cssDir %>lib/*.css'],
          }
        }
      },
      // Static Web Server
      nodestatic: {
        server: {
          options: {
            port: 9009
          }
        }
      },
      svgmin: {
        options: {
          plugins: [
            {
              removeViewBox: false
            }, {
              removeUselessStrokeAndFill: false
            }, {
              cleanupIDs: false
            }
          ]
        },
        dist: {
          files: {
            'img/svg-icons.min.svg': 'img/svg-icons.svg'
          }
        }
      },
      svgstore: {
        options: {
          prefix: 'Icon-',
          cleanup: ['fill','viewbox']
        },
        default: {
          files: {
            'img/svg-icons.svg': ['<%= _globalConfig.iconsDir %>*.svg'],
          },
        },
      },
      // Less Compiler
      less: {
        options: {
          ieCompat: true,
          sourceMap: true,
          sourceMapBasepath: '_less',
          outputSourceFiles: true
        },
        dev: {
          files: {
            '<%= _globalConfig.cssDir %><%= pkg.name %>.css': '<%= _globalConfig.lessDir %><%= pkg.name %>.less'
          }
        }
      },
      handlebars: {
        compile: {
          files: {
            // "<%= _globalConfig.jsDir %>lib/_templates.js": ['<%= _globalConfig.templateDir %>*.hbs']
            "<%= _globalConfig.jsDir %>temptpl.js": ['<%= _globalConfig.templateDir %>*.hbs']
          }
        }
      },
      watch: {
        css: {
          // Watches LESS file changes then triggers LESS compile
          files: ['<%= _globalConfig.lessDir %>**/*.less'],
          tasks: ['less:dev',]
        },
        suit: {
          // Watches Site CSS file for changes then passes to Suit-CSS preprocessor
          files: ['<%= _globalConfig.cssDir %><%= pkg.name %>-suit.css','<%= _globalConfig.cssDir %>lib/*.css'],
          tasks: ['suitcss']
        },
        svg: {
          files: ['<%= _globalConfig.iconsDir %>*.svg'],
          tasks: ['svgstore','svgmin']
        },
        hbs: {
          files: ['<%= _globalConfig.templateDir %>*.hbs'],
          tasks: ['handlebars']
        }
        // js: {
        //   files: ['<%= _globalConfig.jsDir %>**/*.js'],
        //   tasks: ['import:dev']
        // },
        // svg: {
        //   files: ['<%= _globalConfig.iconsDir %>*.svg'],
        //   tasks: ['svgstore','svgmin']
        // }
      },

    });

    // Load Plugins Found in package.json
    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

    // Grunt Tasks
    grunt.registerTask('prepsvg',['svgstore','svgmin']);
    grunt.registerTask('suitup',['watch:suit']);
    grunt.registerTask('default', ['watch']);

  };
}());
(函数(){
"严格使用",;
module.exports=函数(grunt){
//全局变量
变量_globalConfig={
lessDir:“_less/”,
cssDir:'css/',
jsDir:'js/',
iconsDir:'assets/icoMoon/SVG/',
templateDir:'TENTPL/'
};
//项目配置。
grunt.initConfig({
//全局变量
_全球配置:_globalConfig,
pkg:grunt.file.readJSON('package.json'),
//文件包括:,https://github.com/vanetix/grunt-includes
//TODO:设置这个。
包括:{
档案:{
src:['path/to/foo.html','path/to/bar.html'],//源文件
dest:'tmp',//目标目录
扁平化:是的,
cwd:‘.’,
选项:{
沉默:是的,
横幅:“”
}
}
},
//CSS预处理器
suitcss:{
选项:{
//特定于任务的选项在这里。
符合:错误
},
你的目标:{
档案:{
'-suit.dev.css':['lib/site.css','lib/*.css'],
}
}
},
//静态Web服务器
节点状态:{
服务器:{
选项:{
港口:9009
}
}
},
斯维格明:{
选项:{
插件:[
{
removeViewBox:false
}, {
移除未使用的行程和填充:false
}, {
cleanupIDs:false
}
]
},
地区:{
档案:{
“img/svg icons.min.svg”:“img/svg icons.svg”
}
}
},
svgstore:{
选项:{
前缀:“图标-”,
清理:['fill','viewbox']
},
默认值:{
档案:{
'img/svg icons.svg':['*.svg'],
},
},
},
//少编译器
减:{
选项:{
ieCompat:是的,
sourceMap:true,
sourceMapBasepath:“\u less”,
outputSourceFiles:true
},
开发人员:{
档案:{
“.css”:“.less”
}
}
},
车把:{
汇编:{
档案:{
//“lib/_templates.js”:['*.hbs']
“testpl.js”:['*.hbs']
}
}
},
观察:{
css:{
//监视更少的文件更改,然后触发更少的编译
文件:['**.less'],
任务:['less:dev',]
},
诉讼:{
//监视站点CSS文件的更改,然后根据CSS预处理器进行传递
文件:['-suit.css','lib/*.css'],
任务:['suitcss']
},
svg:{
文件:['*.svg'],
任务:['svgstore','svgmin']
},
哈佛商学院:{
文件:['*.hbs'],
任务:[“把手”]
}
//js:{
//文件:['**.js'],
//任务:['import:dev']
// },
//svg:{
//文件:['*.svg'],
//任务:['svgstore','svgmin']
// }
},
});
//加载package.json中的插件
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
//繁重的任务
registerTask('prepsvg',['svgstore','svgmin']);
grunt.registerTask('suitup',['watch:suit']);
registerTask('default',['watch']);
};
}());
在这里找到了答案:


我们能看看你的文件吗?
handlebars: {
    compile: {
        files: {
            "public/js/templates/templates.js": "public/js/templates/*.hbs"
        },
        options: {
            namespace: 'Handlebars.templates',
            processName: function(filePath) {
                var pieces = filePath.split("/");
                return pieces[pieces.length - 1].replace('.hbs', ''); 
                }
        }
    }
}