目标
使用Gulp来呈现一个Jade模板,该模板遍历JSON数组中的项。
问题
尽管我可能会尝试,但我无法找到允许我访问JSON对象中字段的解决方案。我已经逐字逐句地学习了4个单独的教程,最后我总是学习cannot read property 'length' of undefined。
代码
items.json
{
"wishlistItems": [
{
"name": "Boots",
"price": 69.95,
"notes": "Size 10"
}
]
}index.jade
doctype html
html
body
ul
each item in wishlistItems
li=item.namegulpfile.js
const gulp = require('gulp');
const jade = require('gulp-jade');
const data = require('gulp-data');
gulp.task('default', ['build-jade']);
gulp.task('build-jade', () => {
gulp.src('./src/index.jade')
.pipe(data(file => require('./src/items.json')))
.pipe(jade({locals: {}}))
.pipe(gulp.dest('./dist/'));
});发布于 2016-06-08 09:11:16
https://stackoverflow.com/questions/37697032
复制相似问题