更改模板标签后,John Resig的“微模板”(Syntax Error)的语法错误<#{%{{etc [英] Syntax Error with John Resig's Micro Templating after changing template tags <# {% {{ etc
本文介绍了更改模板标签后,John Resig的“微模板”(Syntax Error)的语法错误<#{%{{etc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我,为什么它不工作?
这是模板
< script type =text / htmlid = row_tmpl>
测试内容{%= id%} {%= name%}
< / script>
引擎的修改部分
str
.replace(/ [\r\t\\\
] / g,)
.split({%)。 (\t)
.replace(/((^ |%>)[^ \t] *)'/ g,$ 1\r)
.replace(/ \t =(。*?)%> / g,',$ 1,')
.split(\t)。join(');)
。 split(%})。join(p.push(')
.split(\r)。join(\\\)
+' ;} return p.join(''););
和javascript
var dataObject = {id:27,name:some more content};
var html = tmpl(row_tmpl,dataObject);结果,你可以看到= id和=名字似乎是在错误的地方?
除了将模板语法块从<%%>更改为{%%}之外,我没有更改任何内容。
这是来自Firefox。
错误:语法错误
行:30,列:89
源代码:
var p = [] ,print = function(){p.push.apply(p,arguments);}; with(obj){p.push('test content'); = idp.push(''); = namep.push ');} return p.join('');
解决方案
当您修改引擎时,您忘了更改这些行:
.replace(/((^ |%>)[^ \t] *)'/ $ 1\r)
/ pre>
.replace(/ \t =(。*?)%> / g,',$ 1,')
到:
.replace(/(( ^ |%\})[^ \t] *)'/ g,$ 1\r)
.replace(/ \t =(。*?)%\} / g, ',$ 1,')
I'm having a bit of trouble with John Resig's Micro templating.
Can anyone help me with why it isn't working?
This is the template
<script type="text/html" id="row_tmpl"> test content {%=id%} {%=name%} </script>
And the modified section of the engine
str .replace(/[\r\t\n]/g, " ") .split("{%").join("\t") .replace(/((^|%>)[^\t]*)'/g, "$1\r") .replace(/\t=(.*?)%>/g, "',$1,'") .split("\t").join("');") .split("%}").join("p.push('") .split("\r").join("\\'") + "');}return p.join('');");
and the javascript
var dataObject = { "id": "27", "name": "some more content" }; var html = tmpl("row_tmpl", dataObject);
and the result, as you can see =id and =name seem to be in the wrong place? Apart from changing the template syntax blocks from <% %> to {% %} I haven't changed anything.
This is from Firefox.
Error: syntax error Line: 30, Column: 89 Source Code: var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push(' test content ');=idp.push(' ');=namep.push(' ');}return p.join('');
解决方案When you modified the engine, you forgot to change these lines:
.replace(/((^|%>)[^\t]*)'/g, "$1\r") .replace(/\t=(.*?)%>/g, "',$1,'")
to this:
.replace(/((^|%\})[^\t]*)'/g, "$1\r") .replace(/\t=(.*?)%\}/g, "',$1,'")
这篇关于更改模板标签后,John Resig的“微模板”(Syntax Error)的语法错误<#{%{{etc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文