Ember.js 如何绑定集合中给定项的属性?
我在Ember.ArrayController中有一个视频列表,我使用{{each}}帮助器在视图中呈现该列表,视频对象有一个url属性:Ember.js 如何绑定集合中给定项的属性?,ember.js,Ember.js,我在Ember.ArrayController中有一个视频列表,我使用{{each}}帮助器在视图中呈现该列表,视频对象有一个url属性: {{#each App.videosController}} <li>{{url}}</li> {{#view Em.Button action="play" target="App.videoPlayer"}}Play{{/view}} {{/each}} 当我点击
{{#each App.videosController}}
<li>{{url}}</li>
{{#view Em.Button action="play" target="App.videoPlayer"}}Play{{/view}}
{{/each}}
当我点击按钮时,如何将url发送给我的播放器?我不知道该怎么做。类似的方法应该可以:
{{#each App.videosController}}
<li>{{url}}</li>
{{#view Em.Button contentBinding="this" action="play" target="App.videoPlayer"}}Play{{/view}}
{{/each}}
App.videoPlayer = Em.Object.create({
content: null,
url: null,
play: function(e){
var itemUrl = Ember.getPath(this, 'content.url');
Ember.set(this, 'url', itemUrl);
}
});
{{{每个App.videoscocontroller}
{{url}}
{{{#查看Em.Button contentBinding=“this”action=“play”target=“App.videoPlayer”}}播放{{/view}
{{/每个}}
App.videoPlayer=Em.Object.create({
内容:空,
url:null,
播放:功能(e){
var itemUrl=Ember.getPath(这是“content.url”);
Ember.set(这个'url',itemUrl);
}
});
重要的部分是:
contentBinding=“this”
。这会将您收藏的单件物品的内容发送到您的视图以供使用。谢谢。它现在可以工作了,我只通过Ember.getPath(e,…)更改Ember.getPath(这个…)
{{#each App.videosController}}
<li>{{url}}</li>
{{#view Em.Button contentBinding="this" action="play" target="App.videoPlayer"}}Play{{/view}}
{{/each}}
App.videoPlayer = Em.Object.create({
content: null,
url: null,
play: function(e){
var itemUrl = Ember.getPath(this, 'content.url');
Ember.set(this, 'url', itemUrl);
}
});