Skip to content

Instantly share code, notes, and snippets.

@AshleyGrant
Last active May 13, 2016 01:34
Show Gist options
  • Save AshleyGrant/af3af031c5acc4c46407679f5ab1376b to your computer and use it in GitHub Desktop.
Save AshleyGrant/af3af031c5acc4c46407679f5ab1376b to your computer and use it in GitHub Desktop.
Editing an item in a list
<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>
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;
}
}
<!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