30 lines
995 B
Plaintext
30 lines
995 B
Plaintext
class Model {
|
|
width: Number
|
|
color: String
|
|
label: String
|
|
function getWidth(self: Model): Number { return self.width }
|
|
function getColor(self: Model): String { return self.color }
|
|
function getLabel(self: Model): String { return self.label }
|
|
function expand(self: Model, event: Event): Unit {
|
|
self.width = 260
|
|
self.color = "#237A45"
|
|
self.label = "绑定已更新"
|
|
}
|
|
}
|
|
model = Model(120, "#526AC7", "点击更新共享对象")
|
|
rect = RectBlock(120, 40, 8, "#526AC7")
|
|
label = TextBlock("初始化")
|
|
widthBinding = rect.bind("width", model.getWidth)
|
|
colorBinding = rect.bind("color", model.getColor)
|
|
labelBinding = label.bind("text", model.getLabel)
|
|
button = Button("更新宽度、颜色和文字")
|
|
clickConnection = button.on("click", model.expand)
|
|
root = Column(24, 16, label, rect, button)
|
|
page = Page()
|
|
page.title = "通用属性绑定"
|
|
page.render(root)
|
|
second = Page()
|
|
second.title = "同一组 Block"
|
|
second.render(root)
|
|
page.activate()
|