Skip to content

Instantly share code, notes, and snippets.

@eppleton
Forked from eppleton/Todo.java
Last active October 19, 2015 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eppleton/4d95745cfd620eb7a919 to your computer and use it in GitHub Desktop.
Save eppleton/4d95745cfd620eb7a919 to your computer and use it in GitHub Desktop.
Knockout API Tutorial - Sample 2
<html>
<head>
<title>PersonView</title>
</head>
<body>
<div data-bind="foreach: persons" > <span data-bind="text: name"></span> is <span data-bind="text: age"></span> years old.</div>
</body>
</html>
package com.dukescript.tutorial;
import net.java.html.json.Model;
import net.java.html.json.Property;
@Model(className = "PersonList", properties = {
@Property(name = "persons", type = Person.class, array = true)})
public class ViewModel {
@Model(className = "Person", properties = {
@Property(name = "name", type = String.class),
@Property(name = "age", type = int.class)})
public static class PersonModel {}
static {
ViewModel.onPageLoad();
}
public static void onPageLoad() {
PersonList personList = new PersonList(new Person("Bob", 123));
personList.getPersons().add(new Person("Bill", 132));
personList.getPersons().add(new Person("Peter", 111));
personList.applyBindings();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment