From a2d1ee8ca9b22481b7909b7a49c2097f27702259 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 7 Jul 2024 02:09:21 +0800 Subject: [PATCH] refactor: Add conditional hiding of elements in forStatementNode --- sui/core/parser.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sui/core/parser.go b/sui/core/parser.go index 45c6e3fe6..2d7241e97 100644 --- a/sui/core/parser.go +++ b/sui/core/parser.go @@ -481,6 +481,24 @@ func (parser *TemplateParser) forStatementNode(sel *goquery.Selection) { parser.data[indexVarName] = idx // parser attributes + // Copy the if Attr from the parent node + if ifAttr, exists := new.Attr("s:if"); exists { + + res, err := parser.data.Exec(ifAttr) + if err != nil { + parser.errors = append(parser.errors, fmt.Errorf("if statement %v error: %v", parser.sequence, err)) + setError(new, err) + parser.show(new) + itemNodes = append(itemNodes, new.Nodes...) + continue + } + + if res == true { + parser.hide(new) + continue + } + } + parser.parseElementAttrs(new) parser.parsed(new)