Mini App Document Mini App Document
  • Start
  • Configuration
  • Framework
  • Custom Components
  • Basic ability
  • Configuration
  • Interface
  • FXML syntax
  • FXS syntax
API
Components
IDE
  • Developer
  • Operator
  • Start
  • Configuration
  • Framework
  • Custom Components
  • Basic ability
  • Configuration
  • Interface
  • FXML syntax
  • FXS syntax
API
Components
IDE
  • Developer
  • Operator
  • Configuration

  • Interface

  • FXML syntax

    • Introduction to FXML
    • Data binding
    • List rendering
    • Conditional rendering
      • 1. wx:if
      • 2. block wx:if
    • Template
    • Quote
  • FXS syntax

  • Framework
  • FXML syntax
2022-08-09
Directory

Conditional rendering

# 1. wx:if

In the framework, use 'wx:if=""' to determine if the block needs to be rendered:

<view wx:if="{{condition}}"> True </view>

You can also add an else block with 'wx:elif and 'wx:else':

<view wx:if="{{length > 5}}"> 1 </view>
<view wx:elif="{{length > 2}}"> 2 </view>
<view wx:else> 3 </view>

# 2. block wx:if

Because 'wx:if' is a control property, it needs to be added to a label. If you want to determine multiple component labels at once, you can wrap multiple components with a single '' label and use 'wx:if' on top to control the properties.

<block wx:if="{{true}}">
  <view> view1 </view>
  <view> view2 </view>
</block>

Please note

'' is not a component, it is just a wrapper element, does not do any rendering in the page, and only accepts the control attributes.

Because templates in 'wx:if' may also contain data binding, the framework has a local rendering process when the conditional value of 'wx:if' is switched, as it ensures that the condition block is destroyed or re-rendered on the switch.

At the same time, 'wx:if' is also lazy, if the initial rendering condition is 'false', the framework does nothing, and only starts local rendering when the condition first becomes true.

In contrast, 'hidden' is much simpler, with components always being rendered, with simple controls on showing and hiding.

In general, 'wx:if' has a higher switching consumption and 'hidden' has a higher initial rendering consumption. Therefore, in scenarios where frequent switching is required, it is better to use 'hidden', and 'wx:if' is better if conditions are unlikely to change at runtime.

Last update: 2022/08/11, 20:42:12
List rendering
Template

← List rendering Template→

Copyright © 2020-2024 Neuxnet
  • Follow System
  • Light Mode
  • Dark Mode
  • Reading Mode