global cfgModel
global mainRoll
--需求 双向绑定
--调节ui model刷新
--调节model ui刷新 (ui可能不存在)
--控制器 以model数据为准 可set 可get
----
struct cfgModel
(
age = 0,
fn set_age val type:#_ =
(
age = val
if type != #uic do mainRoll.spn1.value = val
)
)
cfgModel = cfgModel()
----
try(destroyDialog mainRoll)catch()
rollout mainRoll ""
(
global spn1
button btn1 "click +" align:#center
spinner spn1 "" align:#center
on spn1 changed val do cfgModel.set_age val type:#uic
on btn1 pressed do
(
cfgModel.set_age (cfgModel.age += 1)
)
)
createDialog mainRoll
/*
外部调用
cfgModel.set_age 30 --设置
cfgModel.age --获取
*/
/*
模板操作期望
startRoll #rollname "标题" modelName:"cfgModel"
addEditText #edt1 "" dataBinding:"age"
addSpinner #spn1 "" dataBinding:"age"
*/
但写起来不是很顺手,后来改成了全部以ui为核心,get 和 set 都通过ui状态来操作