I’m a Fuse really really absolute beginner and I have basic knowledge of Javascript too, but I really want to make an app with Fuse and I’m doing all my best to learn.
I would like to display (list) some JSON data. I used as code the example in the “Fetching and displaying data” video tutorial. The problem I’m trying to solve is that my JSON data has Base64 encoded images
that I would like to display but I don’t understand how to use getImageFromBase64(base64)
.
The Base64
string is saved in the imageencoded
JSON key and it has the prefix string data:image/png;base64,
or data:image/jpg;base64,
.
This is my .unoproj
file:
{
"RootNamespace":"",
"Packages": [
"Fuse",
"FuseJS",
"Fuse.ImageTools"
],
"Includes": [
"*"
]
}
And this is the code:
<App>
<DockPanel>
<JavaScript>
var Observable = require("FuseJS/Observable");
var Image = require("FuseJS/ImageTools");
var imageencoded = Observable();
var title = Observable();
var errorMessage = Observable("");
fetch("http://www.triestenascosta.it/data.json")
.then(function(result) {
if(result.status !== 200){
errorMessage.value = "Error " + result.status;
return;
}
result.json().then(function(data){
for(var i = 0; i < 10; i++){
var item = data[i];
title.add(item);
imageencoded.add(item);
}
});
}).catch(function(error) {
errorMessage.value ="Oh no!";
});
module.exports={
title: title,
imageencoded: imageencoded,
errorMessage: errorMessage
};
</JavaScript>
<StatusBarBackground DockPanel.Dock="Top" />
<Text TextColor="#a94442" Value="{errorMessage}" Alignment="Center" />
<ScrollView ClipToBounds="true">
<StackPanel>
<Each Items="{title}">
<DockPanel Margin="0, 0, 0, 10">
<Text Value="{title}" TextWrapping="Wrap" Alignment="CenterLeft" Margin="10" />
</DockPanel>
</Each>
</StackPanel>
</ScrollView>
</DockPanel>
</App>
Would you kindly add the getImageFromBase64(base64)
part of code so that I understand how it works and how Javascript promises work?
I did add something like this var Image = require("FuseJS/ImageTools");
but after this I really don’t know how to continue.
P.S. The example of the video tutorial works perfectly in local preview, but it does not on my Samsung S3 Mini (Android 4.4), nor on my Huawei Honor 7 (Android 6) as the image placeholders are not displayed. Locally the preview correctly shows the square image placeholders and the list of strings, but on the devices only the list of strings is shown.
Many thanks