Skip to content

Instantly share code, notes, and snippets.

@jtulach
Last active September 4, 2017 18:31
Show Gist options
  • Save jtulach/992904715978478ed14a210b734a21f5 to your computer and use it in GitHub Desktop.
Save jtulach/992904715978478ed14a210b734a21f5 to your computer and use it in GitHub Desktop.
Compute function matrix
<h3>Your Results</h3>
<input type="checkbox" data-bind="checked: all"> Show all
<span data-bind="foreach: results">
<br data-bind="visible: y() == 1"/>
<span data-bind="visible: $root.all() || correct()">
f(<span data-bind="text:x"></span>,
<span data-bind="text:y"></span>) =
<span data-bind="text:f"></span>
</span>
</span>
package dew.demo.quiz;
import net.java.html.json.*;
@Model(className="UI", properties={
@Property(name="all", type=boolean.class),
@Property(name="results", type=Task.class, array=true)
})
class UICntrl {
static {
UI ui = new UI(true);
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
ui.getResults().add(new Task(i, j));
}
}
ui.applyBindings();
}
@Model(className="Task", properties={
@Property(name="x", type=int.class),
@Property(name="y", type=int.class)
})
static class TaskCntrl {
@ComputedProperty
static int f(int x, int y) {
return x * y - 5 ;
}
@ComputedProperty
static boolean correct(int x, int y) {
return f(x, y) == 13;
}
}
}
@jtulach
Copy link
Author

jtulach commented Sep 6, 2016

See this gist alive in a Development Environment for Web.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment