I am trying to figure out how to do a multiline ListElement property.
I have a ListModel with ListElements as follows:
ListElement {
key: "key";
value: 1;
description: "Very long, full paragraph description that extends way off the screen which I would like to wrap in code nicely."
}
I can wrap it by simply entering a newline, but then the following lines are not lined up with the block of text.
description: "Very long, full paragraph description
that extends way off the screen which I would like to
wrap in code nicely."
When I try to tab over the text to line it up, it causes massive whitespace when the description is printed to screen (which makes sense, but obviously not what I want).
description: "Very long, full paragraph description
that extends way off the screen which I would like to
wrap nicely in code."
Very long, full paragraph description that extends way off the screen which I would like to
wrap in code nicely.
I have tried concatenating via ‘+’, but that produces an error: ListElement: Cannot use script for property value
.
I have tried using backslashes like I do in the .pro file, but that does not work, either.
Newline characters work, but they do not matter, as they do not solve the whitespace issue.
Very long, full paragraph description
that extends way off the screen which I would like to
wrap in code nicely.
If anyone has any ideas, I would appreciate them.
2
Answers
I don’t have a direct solution for the implementation you are using with creating ListElements directly like that. But the .append() method of the ListModel does take JS objects as arguments. And those support multiline strings. So instead of creating ListElements like that you could just append them on component completion like this:
Firstly, you can consider using Javascript backtick notation to declare a multiline string.
Beyond that, you may find
ListElement
declaration to be restrictive not supporting Javascript expressions, e.g.Date.now()
. In those cases, you can consider using imperative code. If you want some semblance of declarative you can declare a Javascript array of objects and iterate through it.When rendering, you may also consider using
wrapMode: Text.Wrap
to apply additional word wrapping to format your text.You can Try it Online!