-
-
Save webOS101/1c1254f2a7879e25e834 to your computer and use it in GitHub Desktop.
RestaurantRepeater with RestaurantView
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: [{ kind: 'RestaurantView' }] | |
}); | |
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: 'RestaurantView', | |
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: '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 with RestaurantView | |
description: A restaurant list that reuses the RestaurantView | |
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