Last active
August 29, 2015 14:09
-
-
Save olizilla/7409f4a1f0c287a13342 to your computer and use it in GitHub Desktop.
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>selector</title> | |
</head> | |
<body> | |
<h1>Welcome to Meteor!</h1> | |
{{> hello}} | |
</body> | |
<template name="hello"> | |
<select> | |
{{#each things}} | |
<option value="{{_id}}">{{name}}</option> | |
{{/each}} | |
</select> | |
</template> |
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
Things = new Mongo.Collection('things') | |
if (Meteor.isServer) { | |
Meteor.publish('allThings', function () { | |
return Things.find() | |
}) | |
} | |
if (Meteor.isClient) { | |
Template.hello.helpers({ | |
things: function () { | |
return Things.find({}, {sort:[["name", "desc"]]}) | |
} | |
}) | |
Template.hello.events({ | |
'change select': function (evt, tpl) { | |
console.log('selected', evt.target.value) | |
} | |
}) | |
Meteor.subscribe('allThings', function (){ | |
if (Things.find().count() !== 0) return | |
Things.insert({name: 'apple'}) | |
Things.insert({name: 'shoe'}) | |
Things.insert({name: 'Bovril'}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment