Skip to content

Instantly share code, notes, and snippets.

@beames
Created August 22, 2014 13:12
Show Gist options
  • Save beames/53556b3a472f0c3061a6 to your computer and use it in GitHub Desktop.
Save beames/53556b3a472f0c3061a6 to your computer and use it in GitHub Desktop.
Ember Starter Kit Ember.Select Selection Binding // source http://jsbin.com/ramero/2
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Ember.Select Selection Binding" />
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script>
<script src="http://builds.emberjs.com/tags/v1.6.1/ember.js"></script>
<style id="jsbin-css">
/* Put your CSS here */
html, body {
margin: 20px;
}
</style>
</head>
<body>
<script type="text/x-handlebars" >
{{view Ember.Select contentBinding="ResAdmin.adminController" selectionBinding="ResAdmin.adminController.selection" optionLabelPath="content.name" optionValuePath="content.id" }}
{{view ResAdmin.Foo}}
Selected: {{ResAdmin.selectedRestaurant.priceCategory.name}}
</script>
<script id="jsbin-javascript">
ResAdmin = Ember.Application.create({});
ResAdmin.adminController = Ember.ArrayProxy.create({
selection: null,
content: [
{
id: '92E9862E-DAE5-4CC8-ACDF-7E6418641F7D',
name: "$"},
{
id: '889C0E73-1587-41D5-8073-FD29FF76CF00',
name: "$$"},
{
id: '47A56B26-A64A-4967-A9F6-B9D69B2CA145',
name: "$$$"},
{
id: '417993DB-48BF-4BA9-BE0A-D6A53C6D8325',
name: "$$$$"}
],
getObjectById: function(id) {
return this.get('content').filterProperty('id', id).get('firstObject');
}
});
ResAdmin.selectedRestaurant = Ember.Object.create({
priceCategoryBinding: 'ResAdmin.adminController.selection'
});
ResAdmin.Foo = Ember.Select.extend({
contentBinding: "ResAdmin.adminController",
selectionBinding: "content.selection",
optionLabelPath: "content.name",
optionValuePath: "content.id"
});
var defaultItem = ResAdmin.adminController.getObjectById('47A56B26-A64A-4967-A9F6-B9D69B2CA145');
console.log(defaultItem);
ResAdmin.adminController.set('selection', defaultItem);
</script>
</body>
</html>
/* Put your CSS here */
html, body {
margin: 20px;
}
ResAdmin = Ember.Application.create({});
ResAdmin.adminController = Ember.ArrayProxy.create({
selection: null,
content: [
{
id: '92E9862E-DAE5-4CC8-ACDF-7E6418641F7D',
name: "$"},
{
id: '889C0E73-1587-41D5-8073-FD29FF76CF00',
name: "$$"},
{
id: '47A56B26-A64A-4967-A9F6-B9D69B2CA145',
name: "$$$"},
{
id: '417993DB-48BF-4BA9-BE0A-D6A53C6D8325',
name: "$$$$"}
],
getObjectById: function(id) {
return this.get('content').filterProperty('id', id).get('firstObject');
}
});
ResAdmin.selectedRestaurant = Ember.Object.create({
priceCategoryBinding: 'ResAdmin.adminController.selection'
});
ResAdmin.Foo = Ember.Select.extend({
contentBinding: "ResAdmin.adminController",
selectionBinding: "content.selection",
optionLabelPath: "content.name",
optionValuePath: "content.id"
});
var defaultItem = ResAdmin.adminController.getObjectById('47A56B26-A64A-4967-A9F6-B9D69B2CA145');
console.log(defaultItem);
ResAdmin.adminController.set('selection', defaultItem);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment