流星叶片模板抛出“同一分支中的第二界标". for循环中的异常 [英] metor blade template throws "second landmark in same branch" exception in for loop

查看:100
本文介绍了流星叶片模板抛出“同一分支中的第二界标". for循环中的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个for循环,我想在其中包含模板视图:

I have a for loop that I want to include a template view in:

table.blade:

table.blade:

#game
    h1= table.name 
        -if( table.playerSitting() )
            a.btn.btn-danger.stand(href="#") Stand
    #table
        -for (var i=0; i<7;i++)
            include 'seat' exposing i

seat.blade:

seat.blade:

- id = 'p' + (i+1)
    div(id="#{id}")
        -if (table.hasAt(i))
            p= table.usernameAt(i)
        -else
            -if( !table.playerSitting() )
                a.btn.btn-inverse.sit(href="#", data-key="#{i}") Sit
            -else
                p &nbsp;

当我第一次加载视图时,一切都绘制良好.但是,如果我坐着或站着,或者去另一张桌子,我会得到这个:

When I first load the view, everything draws fine. But if I sit or stand, or go to another table, I get this:

Exception from Deps recompute: Error: Can't create second landmark in same branch
    at /home/thomporter/meteor/blackjack/views/table.blade:8:4

 6 |        #table
 7 |            -for (var i=0; i<7;i++)
 8 >                include 'seat' exposing i
 9 |    
10 |    

我认为我可以通过创建一个存储用户ID和用户名的座位"集合来解决此问题.表ID,但这似乎很愚蠢.我目前正在使用名为玩家"的表的数组属性,每个席位的索引为0-6 ...至少是这样. =)

I figure I can fix this by creating a "seats" collection that stores the user id & table ids, but that seems silly. I'm currently using an array property of the table called "players", index 0-6 for each seat... at least, that's the idea. =)

我还应该提到我将seat.blade替换为:

I should also mention I replaced seat.blade with:

p hi

没有运气,同样的问题.

and no luck, same issues.

有什么想法吗?

修改
版本信息:
陨石版本0.4.9
流星版本0.5.9(git签出)
刀片3.0.3

Edit
Version Information:
Meteorite version 0.4.9
Meteor version 0.5.9 (git checkout)
Blade 3.0.3

推荐答案

此错误实际上是由于使用普通旧的for循环而不是foreach循环造成的.

This bug is actually a result of using plain-old for loops instead of foreach loops.

foreach区域优于... [常规的循环]不仅 因为易读性和简洁性,但是因为它还提供了Blade 能够更好地与实时页面更新引擎集成 (特别是流星和星火).也就是说,如果实时页面更新 引擎支持跟踪反应式集合,这是最有效的DOM 可能需要执行一些操作以就地更新视图的结果,而无需 重新渲染整个Blade模板.

The foreach region is preferred over ... [regular for loops] not only because of readability and brevity, but because it also provides Blade with the ability to better integrate with live page updating engines (specifically Meteor and Spark). That is, if the live page update engine supports tracking reactive collections, the most efficient DOM operations may occur to update the view's results in-place, without re-rendering the entire Blade template.

在您的情况下,Spark无法重新渲染您包含的模板,因为相同地标的分支匹配.如果使用foreach,此问题将得到解决.

In your case, Spark is failing to re-render your included templates because of matching branches for the same landmark. If you use foreach, this problem is resolved.

但是,在某些情况下(例如您的情况),foreach是不合适的.我认为这里的解决方案是在Blade中创建常规循环"语法来处理循环.因此,我创建了 issue#157 .

However, in some situations (like yours), foreach is not appropriate. I think that the solution here is to create a "regular for loop" syntax within Blade to handle loops. Because of this, I created issue # 157.

这篇关于流星叶片模板抛出“同一分支中的第二界标". for循环中的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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