Skip to content

Instantly share code, notes, and snippets.

@webOS101
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save webOS101/500a5aaafeb37924c745 to your computer and use it in GitHub Desktop.
Save webOS101/500a5aaafeb37924c745 to your computer and use it in GitHub Desktop.
RestaurantRepeater
enyo.ready(function() {
enyo.kind({
name: 'RestaurantRepeater',
kind: 'enyo.DataRepeater',
components: [{
components: [
{ name: 'name' },
{ name: 'cuisine' },
{ name: 'specialty' },
{ name: 'rating' }
],
bindings: [
{ from: 'model.name', to: '$.name.content' },
{ from: 'model.cuisine', to: '$.cuisine.content' },
{ from: 'model.specialty', to: '$.specialty.content' },
{ from: 'model.rating', to: '$.rating.content' }
]
}]
});
enyo.kind({
name: 'RestaurantModel',
kind: 'enyo.Model',
attributes: {
name: 'unknown',
cuisine: 'unknown',
specialty: 'unknown',
rating: 0
},
computed: [
{ method: 'starRating', path: 'rating' }
],
starRating: function() {
var rating = this.get('rating');
return rating + ' star' + ((rating == 1) ? '' : 's');
}
});
enyo.kind({
name: 'RestaurantCollection',
kind: 'enyo.Collection',
model: 'RestaurantModel'
});
enyo.kind({
name: 'MainView',
components: [{ name: 'list', kind: 'RestaurantRepeater' }],
bindings: [
{ from: 'collection', to: '$.list.collection' }
],
create: function() {
this.inherited(arguments);
this.set('collection', new RestaurantCollection([
{
name: 'Orenchi',
cuisine: 'Japanese',
specialty: 'ramen',
rating: 4
}, {
name: 'The Inn at Little Washington',
cuisine: 'New American',
rating: 5
}, {
name: 'The French Laundry',
cuisine: 'French',
rating: 5
}
]));
}
});
new enyo.Application({ name: 'app', view: 'MainView' });
});
name: RestaurantRepeater
description: First pass at creating a restaurant list
authors:
- Roy Sutton
normalize_css: no
@webOS101
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment