Skip to content

Instantly share code, notes, and snippets.

@eppleton
Forked from eppleton/Todo.java
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save eppleton/b981cbcd554f62ba7ab1 to your computer and use it in GitHub Desktop.
Save eppleton/b981cbcd554f62ba7ab1 to your computer and use it in GitHub Desktop.
Knockout API Tutorial - Sample 5
<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>
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