I would like to add line breaks \n
to <Text>
. I noticed that \n
will work fine if passed from Javascript, but it will not when data is fetched in JSON format from a remote server.
Please consider the following sample. The line breaks \n
used in data
and lineBreak
are correctly displayed. The line break used in fetchedData
which is obtained by fetching data via API is ignored despite console.log
shows that there’s a \n
.
<App>
<JavaScript>
var Observable = require("FuseJS/Observable");
var data = Observable();
var fetchedData = Observable();
var lineBreak = Observable("Hello\nWorld");
var json = {
"settings": [
{
about: "Hello\nWorld"
}
]
};
data.replaceAll(json.settings);
fetch("http://www.mindteq.com/api/tsn.php?startup")
.then(function(response) {
if (response.ok) {
return response.json();
} else {
throw Error(response.status);
}
})
.then(function(json) {
fetchedData.replaceAll(json.settings);
fetchedData.forEach(function(settings) {
console.log(settings.announce);
});
}).catch(function(error) {
});
module.exports = {
data: data,
fetchedData: fetchedData,
lineBreak: lineBreak
};
</JavaScript>
<StackPanel>
<Text Value="{lineBreak}" Margin="0,0,0,20" />
<Text Value="{data.about}" Margin="0,0,0,20" />
<Text Value="{fetchedData.announce}" />
</StackPanel>
</App>