Vla*_*kov 6 node.js swig-template
我尝试过json过滤器,但是我发现"json"过滤器找不到错误.我做错了什么?
Error: Filter "json" not found at Object.exports.wrapFilter (......./node_modules/swig/lib/helpers.js:310:11)
<script type="text/javascript">
{{ places|json }}
</script>
Run Code Online (Sandbox Code Playgroud)
对象从mongodb传递
this.displayMainPage = function(req, res, next) {
"use strict";
places.getPlaces(10, function(err, results) {
"use strict";
if (err) return next(err);
return res.render('places_template', {
places: results
});
});
}
Run Code Online (Sandbox Code Playgroud)
编辑:我正在尝试输出json传递给谷歌地图并在html中显示相同的数据
Jon*_*ski 11
对于1.0之前的Swig版本,json过滤器被命名为json_encode:
{{ places|json_encode }}
Run Code Online (Sandbox Code Playgroud)
而且,对于兼容性,1.0和更高版本保持json_encode 作为别名的json.
不过,您还应该考虑升级Swig:
$ npm install swig@0.14
npm WARN deprecated swig@0.14.0: v1.0.0 is a complete rewrite of Swig
from the ground up. Previous versions are no longer supported
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5352 次 |
| 最近记录: |