-
-
Save eppleton/4d95745cfd620eb7a919 to your computer and use it in GitHub Desktop.
Knockout API Tutorial - Sample 2
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> | |
<div data-bind="foreach: persons" > <span data-bind="text: name"></span> is <span data-bind="text: age"></span> years old.</div> | |
</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; | |
@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