-
Notifications
You must be signed in to change notification settings - Fork 208
基础特性
xuwhale6 edited this page Aug 17, 2020
·
1 revision
为控件设置ID
来作为该控件的唯一标识
ui {
--- layout views
Label()
.ID(label1)
.width(100)
.height(100)
.bgColor(200, 0, 0, 0.5)
,
Label("点我")
.bgColor(Color(200, 200, 200, 1))
.padding(10, 20, 10, 20)
.marginTop(10)
.onClick(function()
label1.bgColor(Color(200, 200, 0, 1))
end)
}
引用当前控件本身
ui {
--- layout views
Label("点我")
.width(100)
.height(100)
.bgColor(200, 0, 0, 0.5)
.onClick(function()
self.bgColor(Color(200, 200, 0, 1))
end)
}
使用make_ref
将model
标记为引用传递。
先来看下面的代码:
model(userData)
function updata(model)
model.name = "update"
print(userData.name)
end
---
--- UI
ui {
--- layout views
Label(userData.name)
.width(100)
.height(100)
.bgColor(200, 0, 0, 0.5)
.textAlign(TextAlign.CENTER)
.onClick(function()
--默认是值传递。这里我们想将model作为参数传入函数中,在函数中修改model值,会发现model未被修改。
--updata(userData)
--使用make_ref将model标记为引用传递,并作为函数的参数传入即可实现函数中修改model值。
updata(make_ref(userData))
end)
}
---
--- preview
local function preview()
userData.name = "点我"
end
--默认是值传递。这里我们想将model作为参数传入函数中,在函数中修改model值,会发现model未被修改。
updata(userData)
--使用make_ref将model标记为引用传递,并作为函数的参数传入即可实现函数中修改model值。
updata(make_ref(userData))