我正在使用 Ember 制作一个网络应用程序,您可以在其中查看体育比赛的不同结果。锦标赛视图由具有 2 个插槽的预赛组成,它们都具有“运动员”属性。当你点击一个位置时,运动员进入第二轮。
这是我的看法:
App.SlotView = Em.View.extend({
heat:null,
athlete:null,
tagName:"span",
mouseDown : function(){
//Here's the problem: "this" isn't the original slot, but a new slot which has the original slot in its _context. I'm fixing the error with this:
var target = this._context ? this._context : this;
//Move the athlete forward etc...
//....
}})
以下是我创建新插槽的方法:
//Inside a loop
slot = App.SlotView.create({
athlete:seed,
heat:heat,
round:1,
classNames:['slot-view']
});
//slot is added to a heatview, which is added to App.round1heats
这是模板
<script type="text/x-handlebars">
<div class="row span2">
{{#each App.round1heats}}
{{#view App.HeatView class="clearfix heat round1"}}
{{#each slots}}
<div class="athlete">
{{#view App.SlotView}}
{{athlete.name}}
{{/view}}
</div>
{{/each}}
{{/view}}
{{/each}}
</div>
</script>
还有一个问题是我无法通过 mouseDown 函数中的“this”或“this._context”访问视图元素。element 和 elementId -properties 在两者中都未定义。
我错过了什么?