Last active
December 31, 2015 07:28
-
-
Save wasbazi/7953890 to your computer and use it in GitHub Desktop.
Window vs. Template scope in Meteor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<title>MeteorGame</title> | |
</head> | |
<body> | |
{{> game}} | |
</body> | |
<template name="game"> | |
<h1>Hello World!</h1> | |
<input type="type" id="hidden-input"> | |
<div id="game"></div> | |
<div id="output"> | |
{{> newCharacter}} | |
</div> | |
</template> | |
<template name="newCharacter"> | |
<h5>Select a character</h5> | |
<div id="character-viewer"> | |
<div | |
class="character" | |
style="{{heroPosition}}"></div> | |
</div> | |
<div id="character-selector"> | |
{{#forEach characters}} | |
<div | |
class="character {{selectedClass _key}}" | |
style="{{backgroundPosition}}"></div> | |
{{/forEach}} | |
</div> | |
</template> | |
<script> | |
//other stuff | |
Template.newCharacter.heroPosition = function(){ | |
// this == Window | |
var character = Template.newCharacter.characters[module.getSelectedIdx()]; | |
var charCoords = Template.newCharacter.backgroundPosition.call(character, null, 4); | |
return charCoords; | |
}; | |
// other stuff | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment