art-template
art-template copied to clipboard
关于在渲染的数据时,未定义的根数据不会报错的问题
在模板数据中,未定义的根键值不存在时,并不会报错,但非根键值会正常提示错误。这是否一个缺陷?或者是我打开的方式不对...(使用中遇到有一个根键值名字输错,但没有报错或提示,然后找了很长时间) 版本: [email protected] for browser
<script id="test" type="text/html">
<ul>
{{ foo }} // foo 未定义,但未报错,或提示foo未定义
</ul>
</script>
<script>
var html = '';
html = template('test', {}); // foo未定义
document.write(html);
</script>
<script id="test" type="text/html">
<ul>
{{ boo.foo }} // boo 未定义,但会报错提示 RuntimeError: Cannot read property 'foo' of undefined
</ul>
</script>
<script>
var html = '';
html = template('test', {}); // boo未定义
document.write(html);
</script>
{{ foo }} 是 {{ $data.foo }} 的简写,模板引擎设计是允许 undefined 值的,undefined 不会引起异常,这里可能需要注意下。