如何获取 TemplateCollectionView 中的索引?

发布于 2024-12-06 18:14:43 字数 1023 浏览 4 评论 0原文

所以我按照sproutcore“入门”指南,开始偏离路径,看看我是否可以轻松地实现我的意思。我在这里使用这个模板,它代表文件输入列表:

{{#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 -->

我该怎么做?我在 使用车把页面SC.ArrayController 上的 sproutcore 文档

我看错了吗 地方?我是否正在尝试以另一种更类似芽核的方式做一些我应该做的事情?

So I followed the sproutcore "getting started" guide, and started wandering off the path to see if I could do what I meant easily. And here I am witht this templates, that represents a list of file inputs :

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

Nice. Now what I'd like to do is benefit from the label for attribute to point to the corresponding input. So basically, I'd like to output something like this:

<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 -->

How do I do that? I did not find the answer neither on the using handlebars page nor on the sproutcore documentation on SC.ArrayController

Am I looking in the wrong place? Am I trying to do something I should do in another, more sproutcore-ish way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情丝乱 2024-12-13 18:14:43

我认为做到这一点的唯一方法是在模型中添加一个 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}}

The only way I see to do this is adding an id field in your model.
So you could use this id in the template.

{{#collection SC.TemplateCollectionView contentBinding="Upload.uploadListController"}}
   <label {{bindattr for="content.id"}} >{{content.title}}</label>
   <input {{bindattr id="content.id"}} type="file" name="upload[]"/>
{{/collection}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文