Skip to content

Instantly share code, notes, and snippets.

@olizilla olizilla/things.html
Last active Aug 29, 2015

Embed
What would you like to do?
<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
You can’t perform that action at this time.