Last active
May 13, 2016 01:34
-
-
Save AshleyGrant/af3af031c5acc4c46407679f5ab1376b to your computer and use it in GitHub Desktop.
Editing an item in a list
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> | |
<ul> | |
<li repeat.for="person of people">${person.firstName} ${person.lastName} <button click.delegate="editPerson(person, $index)">Edit</button></li> | |
</ul> | |
<div if.bind="editing"> | |
First Name: <input type="name" value.bind="editModel.firstName" /> | |
Last Name: <input type="name" value.bind="editModel.lastName" /> | |
<button click.delegate="savePerson()">Save</button> | |
<button click.delegate="cancelEdit()">Cancel</button> | |
</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 { | |
editing = false; | |
people = [ | |
{ firstName: 'John', lastName: 'Doe' }, | |
{ firstName: 'Jane', lastName: 'Smith' }, | |
{ firstName: 'Bob', lastName: 'Smith' } | |
]; | |
editPerson(person, index) { | |
this.editing = true; | |
this.editObject = person; | |
this.editModel = Object.assign({},person); | |
} | |
savePerson() { | |
this.editing = false; | |
this.editObject.firstName = this.editModel.firstName; | |
this.editObject.lastName = this.editModel.lastName; | |
this.editObject = null; | |
this.editModel = null; | |
} | |
cancelEdit() { | |
this.personBeingEdited = null; | |
this.editing = false; | |
} | |
} |
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"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://ashleygrant.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
<script src="https://ashleygrant.github.io/rjs-bundle/config.js"></script> | |
<script> | |
require.config({ | |
paths: { | |
"sortable": "https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.4.2/Sortable.min" | |
} | |
}); | |
</script> | |
<script src="https://ashleygrant.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
<script src="https://ashleygrant.github.io/rjs-bundle/bundles/babel.js"></script> | |
<script> | |
require(['aurelia-bootstrapper']); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment