Last active
September 29, 2017 21:18
-
-
Save martonsagi/4514caa6ee7d40df2f7cfe2605451a0e to your computer and use it in GitHub Desktop.
Aurelia - Load array of Enum values
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
<template> | |
<require from="./enum-list"></require> | |
<require from="./keys-value-converter"></require> | |
<h2>Single Dropdown - Dynamic</h2> | |
<label>Type</label> | |
<select class="form-control" value.bind="selectedType"> | |
<option repeat.for="mainKey of data | keys" value="${mainKey}">${mainKey}</option> | |
</select> | |
<br> | |
<enum-list source.bind="data" name.bind="selectedType"></enum-list> | |
<hr> | |
<h2>Single Dropdown - Fixed</h2> | |
<enum-list source.bind="data" name="AbsenceCode"></enum-list> | |
<h2>All Dropdowns</h2> | |
<div class="form-group" repeat.for="mainKey of data | keys"> | |
<enum-list source.bind="data" name.bind="mainKey"></enum-list> | |
</div> | |
</template> |
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
export class App { | |
selectedType = 'AbsenceCode'; | |
data = { | |
"AbsenceCode": { | |
"E": "Excused", | |
"U": "Unexcused" | |
}, | |
"ActiveInactive": { | |
"A": "Active", | |
"I": "Inactive" | |
}, | |
"AuthenticationLog": { | |
"1": "Staff", | |
"2": "ParentAccess", | |
"3": "StudentAccess" | |
}, | |
"YesNo": { | |
"0": "Yes", | |
"1": "No" | |
} | |
}; | |
} |
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
<template> | |
<require from="./keys-value-converter"></require> | |
<label>${name}</label> | |
<select name="${name}" class="form-control"> | |
<option value="">---</option> | |
<option repeat.for="code of source[name] | keys" value="${code}">${source[name][code]}</option> | |
</select> | |
</template> |
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
import {bindable} from 'aurelia-framework'; | |
export class EnumList { | |
@bindable source; | |
@bindable name; | |
} |
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
<!doctype html> | |
<html> | |
<head> | |
<title>Aurelia</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | |
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> | |
<script> | |
require(['aurelia-bootstrapper']); | |
</script> | |
</body> | |
</html> |
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
export class KeysValueConverter { | |
toView(obj) { | |
return Reflect.ownKeys(obj).filter(x => x !== '__observers__'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment