Last active
October 2, 2016 22:56
-
-
Save geleto/69bb3f099a1dfb788616178a0fed1a09 to your computer and use it in GitHub Desktop.
Select bound to a sub-property does not update properly when changing the parent property
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> | |
<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> | |
<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> | |
<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> | |
<button click.delegate="selectModel(0)">Select Model 0</button> | |
<button click.delegate="selectModel(1)">Select Model 1</button> | |
<button click.delegate="selectModel(2)">Select Model 2</button> | |
</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
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]; | |
} | |
selectModel(index){ | |
this.selectedCar.selectedModel = this.selectedCar.models[index]; | |
} | |
} |
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://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