-
-
Save eppleton/b981cbcd554f62ba7ab1 to your computer and use it in GitHub Desktop.
Knockout API Tutorial - Sample 5
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
<html> | |
<head> | |
<title>PersonView</title> | |
</head> | |
<body> | |
<ol data-bind="foreach: persons"> | |
<li><span data-bind="text: name"></span> is | |
<span data-bind="text: age"></span> years old. <button data-bind="click: $parent.remove">Delete</button> | |
<span data-bind="text: address().city"></span>, | |
<span data-bind="text: address().street"></span> | |
</li> | |
</ol> | |
</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
package com.dukescript.tutorial; | |
import net.java.html.json.Model; | |
import net.java.html.json.Property; | |
import net.java.html.json.ComputedProperty; | |
import net.java.html.json.Function; | |
@Model(className = "PersonList", properties = { | |
@Property(name = "persons", type = Person.class, array = true)}) | |
public class ViewModel { | |
static{ | |
ViewModel.onPageLoad(); | |
} | |
@Model(className = "Address", properties = { | |
@Property(name = "city", type = String.class), | |
@Property(name = "street", type = String.class) | |
}) | |
public static class AddressModel{} | |
@Model(className = "Person", properties = { | |
@Property(name = "name", type = String.class), | |
@Property(name = "age", type = int.class), | |
@Property(name="address", type = Address.class) | |
}) | |
public static class PersonModel { | |
@Function | |
public static void increaseAge(Person person){ | |
person.setAge(person.getAge()+1); | |
} | |
} | |
@Function | |
public static void remove(PersonList model, Person data){ | |
model.getPersons().remove(data); | |
} | |
public static void onPageLoad() { | |
PersonList personList = new PersonList(new Person("Geertjan", 22, new Address("Amsterdam", "Codersgracht 11001010"))); | |
personList.getPersons().add(new Person("Toni", 19,new | |
Address("Amsterdam", "Bergmannstr. 66 "))); | |
personList.applyBindings(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment