ejs 报错
来源:4-2 第四天 封装消息响应模块
一半火焰
2016-10-26
'use strict' var ejs = require('ejs'); var heredoc = require('heredoc'); var tpl = heredoc(function() {/* <xml> <ToUserName><![CDATA[<%= toUserName %>]]></ToUserName> <FromUserName><![CDATA[<%= fromUserName %>]]></FromUserName> <CreateTime><%= createTime %></CreateTime> <MsgType><![CDATA[<%= msgType %>]]></MsgType> <% if (msg === 'text) { %> <Content><![CDATA[<%= content %>]]></Content> <% } else if(msgType === 'image') { %> <Image> <MediaId><![CDATA[<%= content.media_id %>]]></MediaId> </Image> <% } else if(msgType === 'voice') { %> <Voice> <MediaId><![CDATA[<%= content.media_id %>]]></MediaId> </Voice> <% } else if(msgType === 'video') { %> <Video> <MediaId><![CDATA[<%= content.media_id %>]]></MediaId> <Title><![CDATA[<%= content.title %>]]></Title> <Description><![CDATA[<%= content.description %>]]></Description> </Video> <% } else if(msgType === 'music') { %> <Music> <Title><![CDATA[<%= content.title %>]]></Title> <Description><![CDATA[<%= content.DESCRIPTION %>]]></Description> <MusicUrl><![CDATA[<%= content.MUSIC_Url %>]]></MusicUrl> <HQMusicUrl><![CDATA[<%= content.HQ_MUSIC_Url %>]]></HQMusicUrl> <ThumbMediaId><![CDATA[<%= content.media_id %>]]></ThumbMediaId> </Music> <% } else if(msgType === 'news') { %> <ArticleCount><%= content.length %></ArticleCount> <Articles> <% content.forEach(function(item){ %> <item> <Title><![CDATA[<%= item.title %>]]></Title> <Description><![CDATA[<%= item.description %>]]></Description> <PicUrl><![CDATA[<%= item.picUrl %>]]></PicUrl> <Url><![CDATA[<%= item.url %>]]></Url> </item> <% }) %> </Articles> <% } %> </xml> */}); // 编译上面的模板 var compiled = ejs.compile(tpl); exports = module.exports = { compiled:compiled }
写回答
2回答
-
Scott
2016-10-26
'use strict' var ejs = require('ejs') var heredoc = require('heredoc') var tpl = heredoc(function() {/* <xml> <ToUserName><![CDATA[<%= toUserName %>]]></ToUserName> <FromUserName><![CDATA[<%= fromUserName %>]]></FromUserName> <CreateTime><%= createTime %></CreateTime> <MsgType><![CDATA[<%= msgType %>]]></MsgType> <% if (msgType === 'text') { %> <Content><![CDATA[<%- content %>]]></Content> <% } else if (msgType === 'image') { %> <Image> <MediaId><![CDATA[<%= content.mediaId %>]]></MediaId> </Image> <% } else if (msgType === 'voice') { %> <Voice> <MediaId><![CDATA[<%= content.mediaId %>]]></MediaId> </Voice> <% } else if (msgType === 'video') { %> <Video> <MediaId><![CDATA[<%= content.mediaId %>]]></MediaId> <Title><![CDATA[<%= content.title %>]]></Title> <Description><![CDATA[<%= content.description %>]]></Description> </Video> <% } else if (msgType === 'music') { %> <Music> <Title><![CDATA[<%= content.title %>]]></Title> <Description><![CDATA[<%= content.description %>]]></Description> <MusicUrl><![CDATA[<%= content.musicUrl %>]]></MusicUrl> <HQMusicUrl><![CDATA[<%= content.hqMusicUrl %>]]></HQMusicUrl> <ThumbMediaId><![CDATA[<%= content.thumbMediaId %>]]></ThumbMediaId> </Music> <% } else if (msgType === 'news') { %> <ArticleCount><%= content.length %></ArticleCount> <Articles> <% content.forEach(function(item) { %> <item> <Title><![CDATA[<%= item.title %>]]></Title> <Description><![CDATA[<%= item.description %>]]></Description> <PicUrl><![CDATA[<%= item.picUrl %>]]></PicUrl> <Url><![CDATA[<%= item.url %>]]></Url> </item> <% }) %> </Articles> <% } %> </xml> */}) var compiled = ejs.compile(tpl) exports = module.exports = { compiled: compiled }
应该是传入的变量不合法或者模板语法有误,比对下这段代码,看看有没有哪里不匹配的
00 -
Scott
2016-10-26
报错是报什么错?
022016-10-26
相似问题