使用“结束”语句时,生态模板呈现整数 [英] Eco template renders integer when using 'end' statement

查看:160
本文介绍了使用“结束”语句时,生态模板呈现整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个pretty简单的骨干视图,我想有呈现HTML的一些块有条件。我看到一个行为,其中有条件地渲染HTML下面有渲染以及一个整数。从我可以告诉,看来当我使用结束语句终止条件块发生。

I have a pretty simple Backbone View that I'd like to have render some blocks of HTML conditionally. I'm seeing a behavior where following the conditionally rendered HTML there is a integer rendered as well. From what I can tell, it seems to happen when I use the end statement to terminate a conditional block.

下面是一些code被证明错误对我来说:

Here's some code that is demonstrating the error for me:

<% if true: %>Hello World!<% end %>

我希望它可以呈现的Hello World!到包含的元素。但是,它的实际渲染的Hello World!2

I would expect this to renderHello World! into the containing element. However, it's actually rendering Hello World!2.

如果我添加若干块在同一个模板:

If I add several of blocks in the same template:

<% if true: %>Foo, <% end %>
<% if true: %>Bar, <% end %>
<% if true: %>Baz<% end %>

我希望它可以呈现富,酒吧,巴兹到包含的元素。但是,它的实际渲染富,2条,5 Baz8 。运行一个稍大组其中后,似乎正在打印的整数通过每次3上升。从阅读过创业板的自述我什么都看不到我做错了。

I would expect this to render Foo, Bar, Baz into the containing element. However, it's actually rendering Foo, 2 Bar, 5 Baz8. After running a somewhat larger set of them, it seems the integer being printed goes up by 3 every time. From reading over the gem's README I can't see anything I'm doing wrong.

任何帮助将是非常美联社preciated!

Any help would be much appreciated!

推荐答案

我有同样的问题。你有没有解决它了吗?

I have the same problem. Have you solved it already?

我认为它引起的如果的被包裹在语句__ obj.push()调用编译后的JS。例如,在我的脚本,有一块$ C $的c

I think it's caused by if statements being wrapped in __obj.push() calls in the compiled JS. For example, in my script, there is a piece of code

<%- if !@blok: %>
  <%- to_html(@create_link('c', @session['course'])) %>
<%- end %>

这被编译成

[1] __out.push(!this.blok ?
[2]  (__out.push('\n '),
[3]   __out.push(to_html(this.create_link('c', this.session['course']))),
[4]   __out.push('\n ')
[5]  ) : void 0)

如果我理解正确的话,这意味着它会先推 \\ n ,该函数的结果,另一个 \\ n 来输出。但最近(4号线)将返回数组,这将是反过来的元素个数由推到数组本身外(1号线)。

If I understand it correctly, it means that it will first push the \n, the result of the function, another \n to the output. But the last push (line 4) will return number of the elements in the array, which will be in turn pushed to the array itself by the outer push (line 1).

我试图修改 Array.prototype.push 返回别的东西,但似乎食堂事情更(因为它是一个核心功能)。

I've tried to change the Array.prototype.push to return something else, but it seems that messes things even more (since it's a core function).

这篇关于使用“结束”语句时,生态模板呈现整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆