Skip to content

Instantly share code, notes, and snippets.

@olizilla
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olizilla/7409f4a1f0c287a13342 to your computer and use it in GitHub Desktop.
Save olizilla/7409f4a1f0c287a13342 to your computer and use it in GitHub Desktop.
<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>
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