Skip to content

Instantly share code, notes, and snippets.

@jdanyow
Forked from geleto/app.html
Created October 3, 2016 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdanyow/82bd060de06f1037807c6f03f15321a3 to your computer and use it in GitHub Desktop.
Save jdanyow/82bd060de06f1037807c6f03f15321a3 to your computer and use it in GitHub Desktop.
Select bound to a sub-property does not update properly when changing the parent property
<template>
<label>Car</label>
<select value.bind="selectedCar">
<option repeat.for="car of cars" model.bind="car">${car.name}</option>)
</select>
<br>
Selected car: <b>${selectedCar.name}</b>
<br>
<button click.delegate="selectCar(0)">Select Audi</button>
<button click.delegate="selectCar(1)">Select BMW</button>
<button click.delegate="selectCar(2)">Select Buick</button>
<br>
<br>
<label>Car.Model</label>
<select value.bind="selectedCar.selectedModel">
<option repeat.for="carModel of selectedCar.models" value.bind="carModel">${carModel}</option>)
</select>
<br>
Selected model: <b>${selectedCar.selectedModel}</b>
<br>
<button click.delegate="selectModel(0)">Select M0</button>
<button click.delegate="selectModel(1)">Select M1</button>
<button click.delegate="selectModel(2)">Select M2</button>
</template>
class Car{
constructor( name, models, selectedModelIndex ) {
this.name = name;
this.models = models;
this.selectedModel = this.models[selectedModelIndex];
}
}
export class App {
constructor(){
this.cars = [new Car( "Audi", ["Audi M0","Audi M1","Audi M2"], 2 ),
new Car( "BMW", ["BMW M0","BMW M1","BMW M2"], 1 ),
new Car( "Buick", ["Buick M0","Buick M1","Buick M2"], 2 )];
this.selectedCar = this.cars[2];
}
selectCar(index){
this.selectedCar = this.cars[index];
this.selectModel(0);
}
selectModel(index){
this.selectedCar.selectedModel = this.selectedCar.models[index];
}
}
<!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://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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment