There's probably something really dumb that I'm missing...
After adding the fixture data to the areas route, the 'areas' template won't render. Everything outside of a template still renders fine. If I comment out the line where I return data to be passed in as the model (i.e. '//return this.store.find('gamearea', 1);'), everything renders as expected, minus the fixture data, obviously. When the template doesn't render properly, Ember doesn't throw any kind of error either.
Eventually, I'll replace the divs inside gamearea entirely with game-zone components. I'm sort of in an in-between stage at the moment. Anyway, thanks for the help.
Here's the relevant code:
//my areas route:
Areas.Router.map(function () {
this.resource('areas', {path: '/'});
});
Areas.AreasRoute = Ember.Route.extend({
model: function () {
return this.store.find('gamearea', 1);
},
actions: {
drawCard: function () {
var $cards = $("#lib1").children();
$("#hand1").append($cards[0]);
var cards = this.store.all('card').filterBy('location', 'lib1');
console.log(cards.objectAt(0).get('location'));
cards.objectAt(0).set('location', "hand1");
console.log(cards.objectAt(0).get('location'));
}
}
});
//the fixture data and model definitions:
Areas.Card = DS.Model.extend({
name: DS.attr("string"),
img: function() {
return ("http://ift.tt/1vX5lUV" + this.get("name") + ".jpg");
}.property("name"),
domid: function () {
return ("card"+this.get("id"));
}.property("id"),
location: DS.attr('string', {defaultValue: "lib1"})
});
Areas.Gamearea = DS.Model.extend({
zones: DS.hasMany('zones', {async: true})
});
Areas.Zone = DS.Model.extend({
name: DS.attr('string'),
cards: DS.hasMany('cards', {async: true}),
zone: DS.belongsTo('zone')
});
Areas.Zones.reopenClass({
FIXTURES: [
{id: 1, name: 'lib1', cards: [1,2,3,4,5]},
{id: 2, name: 'lib2', cards: [6,7,8,9,10]}
]
});
Areas.Cards.reopenClass({
FIXTURES:
[
{
id: 1,
name: "Island",
zone: 1
},{
id: 2,
name: "Jace, the Mind Sculptor",
zone: 1
},{
id: 3,
name: "Island",
zone: 1
},{
id: 4,
name: "Counterspell",
zone: 1
},{
id: 5,
name: "Island",
zone: 1
},
{
id: 6,
name: "Island",
zone: 2
},{
id: 7,
name: "Jace, the Mind Sculptor",
zone: 2
},{
id: 8,
name: "Island",
zone: 2
},{
id: 9,
name: "Counterspell",
zone: 2
},{
id: 10,
name: "Island",
zone: 2
}
]
});
Areas.Gamearea.reopenClass({
FIXTURES:
{
id: 1,
zones: [1,2]
}
});
<script type="text/x-handlebars" data-template-name="areas">
<div id="gamearea">
<div id="top1" class="top p1">Top</div><button id="deck1" class="deck p1" {{action 'drawCard'}}></button><div id="bot1" class="bot p1">Bot</div>
<div id="lib1" class="zone display-zone p1 library">
</div>
{{game-zone cards=model.lib1}}
{{game-zone cards=model.hand1}}
<div id="hand1" class="zone display-zone p1 hand">
</div>
<div id="battlefield1" class="zone display-zone p1 battlefield"></div>
<div id="graveyard1" class="zone display-zone p1 graveyard"></div>
<div id="exile1" class="zone display-zone p1 exile"></div>
<div id="revealed1" class="zone display-zone p1 revealed"></div>
<br>
<hr>
<br>
<div id="top2" class="top p2">Top</div><div id="deck2" class="deck p2"></div><div id="bot2" class="bot p2">Bot</div>
<div id="lib2" class="zone display-zone p2 library"></div>
<div id="hand2" class="zone display-zone p2 hand"></div>
<div id="battlefield2" class="xone display-zone p2 battlefield"></div>
<div id="graveyard2" class="zone display-zone p2 graveyard"></div>
<div id="exile2" class="zone display-zone p2 exile"></div>
<div id="revealed2" class="zone display-zone p2 revealed"></div>
<button type="button" class="btn btn-primary menu-btn">Menu</button>
<button type="button" class="btn btn-success to-top">To Top</button>
</div>
</script>
<script type="text/x-handlebars" data-template-name="components/card-component">
<img {{bind-attr id=card.domid alt=card.name src=card.img}} draggable="true" class="card" {{action "droppedCard" on="drop"}}>
</script>
<script type="text/x-handlebars" data-template-name="components/game-zone">
{{#each card in cards}}
{{card-component card=card}}
{{/each}}
</script>
Aucun commentaire:
Enregistrer un commentaire