@Target(value=METHOD) @Retention(value=SOURCE) public @interface Function
Model can be
annotated by this annotation to signal that they should be available
as functions to users of the model classes. The method
should be non-private, static and return void.
It may take up to two arguments. One argument can be the type of
the associated model class, the other argument can be of any type,
but has to be named data - this one represents the
actual data the function was invoked on. Example:
The above example would render:@Model(className="Names", properties={@Property(name = "selectedName", type=String.class),@Property(name = "names", type=String.class, array = true) }) static class NamesModel {@Functionstatic void nameSelected(Names myModel, String data) { myModel.setSelectedName(data); } static void initialize() { Names pageModel = new Names("---", "Jarda", "Pepa", "Honza", "Jirka", "Tomáš"); pageModel.applyBindings(); } } // associated Knockout HTML page: 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>
--- would be replaced
by selected name.
Try this sample on-line!Copyright © 2014 NetBeans. All Rights Reserved.