2011-09-26 43 views
1

所以我跟着sproutcore "getting started" guide,開始徘徊,看看我能否做到我的意思。在這裏,我witht這個模板,它表示的文件輸入列表:如何獲取TemplateCollectionView中的索引?

{{#collection SC.TemplateCollectionView 
    contentBinding="Upload.uploadListController"}} 
    <label>{{content.title}}</label><input type="file" name="upload[]"/> 
{/collection}} 

尼斯。現在我想要從標籤for屬性中獲益,以指向相應的輸入。所以基本上,我想輸出這樣的東西:

<label for="upload-0">Some label</label> 
<input id="upload-0" type="file" name="upload[]"/> 

<label for="upload-1">Some otherlabel</label> 
<input id="upload-1" type="file" name="upload[]"/> 
<!-- you get it --> 

我該怎麼做?我在using handlebars pagesproutcore documentation on SC.ArrayController

上都找不到答案我在找錯地方?我是否試圖做一些我應該以另一種方式做的事情,更多萌芽的方式?

回答

1

我看到要做到這一點的唯一方法是在模型中添加一個 id字段。 所以你可以在模板中使用這個ID。

{{#collection SC.TemplateCollectionView contentBinding="Upload.uploadListController"}} 
    <label {{bindattr for="content.id"}} >{{content.title}}</label> 
    <input {{bindattr id="content.id"}} type="file" name="upload[]"/> 
{{/collection}} 
+0

我試過了,但是sproutcore用span標籤包裝了帶有{{content.id}}的輸出。我怎樣才能防止這一點? – greg0ire

+0

如果要綁定到屬性,則應該使用'{{bindAttr for =「content-id」}}「。 – Steffen

+0

工程就像一個魅力。公認! – greg0ire