Last active
August 29, 2015 14:06
-
-
Save webOS101/500a5aaafeb37924c745 to your computer and use it in GitHub Desktop.
RestaurantRepeater
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
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' }); | |
}); |
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
name: RestaurantRepeater | |
description: First pass at creating a restaurant list | |
authors: | |
- Roy Sutton | |
normalize_css: no |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try it out on jsFiddle
From: Enyo: Up and Running by Roy Sutton