Skip to content
This repository was archived by the owner on May 27, 2021. It is now read-only.

Access object field in a loop #87

@Namek

Description

@Namek

Current state

I have a collection of objects, this is working:

@LmlAction("blocks")
public Array<Block> getBlocks() {
    return level.blocks;
}
<:foreach element="$blocks">
    <textbutton color="red">{element}</textbutton>
</:foreach>
public class Block {
    public boolean isWritten = false;

    @Override
    public String toString() {
        return isWritten ? "x" : " ";
    }
}

image

Goal

I'd like to colorize "x" blocks to red based on isWritten field.

Problem

Accessing the isWritten field is the unknown to me. How do I do that?

I thought about 2 ways:

  1. pass the element (or index) to a method to evaluate it
  2. access the field directly from the template which doesn't work for me:
<:foreach element="$blocks">
    <textbutton color="red">{element.isWritten}</textbutton>
</:foreach>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions