Skip to content

Instantly share code, notes, and snippets.

@jtulach
Last active October 24, 2015 18:56
Show Gist options
  • Save jtulach/8848505 to your computer and use it in GitHub Desktop.
Save jtulach/8848505 to your computer and use it in GitHub Desktop.
Shows usage of @function callback
Selected name: <span data-bind="text: selectedName"></span>
<ul data-bind="foreach: names">
<li>
<a data-bind="text: $data, click: $root.nameSelected" href="#"></a>
</li>
</ul>
package dew.demo.namesmodel;
import net.java.html.json.Model;
import net.java.html.json.Property;
import net.java.html.json.Function;
@Model(className="Names", properties={
@Property(name = "selectedName", type=String.class),
@Property(name = "names", type=String.class, array = true)
})
class NamesModel {
@Function static void nameSelected(Names myModel, String data) {
myModel.setSelectedName(data);
}
static {
Names pageModel = new Names(
"---", "Jarda", "Pepa", "Honza", "Jirka", "Tomáš"
);
pageModel.applyBindings();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment