attach

Summary

Attaches a view to the model.

Usage

public virtual void attach(View view)

Parameters

view

The view to attach to the model.

Description

Attaches a view to the model. When the model data changes (such as via Model.updateAll()), the attached view(s) will also be updated.

Examples

Full Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import System;
import Altitude.Frontend;
 
// Create the model
class Temperature : Model
{
    Date date;
    double degrees;
 
    Temperature(Date date, double degrees) {
        this.date = date;
        this.degrees = degrees;
    }
 
    void setDegrees(double degrees) {
        this.degrees = degrees;
    }
}
// Create view
class BarChart : View
{
    // ...
}
 
// Instantiate model
Temperature temp = new Temperature(new Date(), 27);
 
// Instantiate view
BarChart barChart = new BarChart();
 
// Attach views to model
temp.attach(barChart);
 
// Initialize views (perform initial render) to the data in `temp`.
// (Assuming data for `temp2` is initially hidden until the user, via
// the user interface, enables it.)
barChart.initialize(temp);
 
// Change the data from the initial render
temp.setDegrees(37);
 
// Update all views
temp.updateAll();

Share

HTML | BBCode | Direct Link