跳转到内容

xml 使用 ts 的变量

ts 中控制 xml 的变量

import {Controller, state} from '@terminus/nusi-sdk';
class Demo extends Controller {
// 加了这个标识在 xml 中会实时生效
@state
// 这样声明 status 就是实例变量,this.env 是获取页面 env
status = this.env.status
// 根据容器数据来做判断
onFormDataLoaded = (record) => {
// 根据表格数据来判断
if (record.birth) {
this.status = true
}
}
// 在某个方法内修改变量
someFunc = () => {
this.status = true
}
}
<Form model="modelKey" onDataLoaded="#{onFormDataLoaded}">
<Field name="birth" />
<!-- 用 ts 中的变量来控制字段显隐 -->
<Field name="name" show="#{!!status}" />
</Form>