Hello,
I have been stuck on this issue for a couple days now. I’m sure it’s a simple fix but I’m new here. I’m trying to pass an ID variable to my Javascript function when a card in the UI is swiped right. Below is my code but I can’t seem to append the ID to my fetch string. Any help is appreciated!
var Observable = require("FuseJS/Observable");
var data = Observable();
var id = Observable(0);
module.exports = {
data: data,
id: id,
};
function addVote() {
var url = 'http://MY_URL/app/add-vote.php?id='+data.id.value;
fetch(url, { method: 'POST' })
.then(function (response) {
return response.text();
})
.then(function (body) {
console.log(body);
});
}
Then the UI:
<Each Items="{data}">
<Panel Margin="0" Height="400" Width="293">
<Rotation Degrees="0" />
<DockPanel Margin="0" Height="100%" Width="100%">
<Grid Columns="auto,1*,auto" Margin="0,14,0,5" Dock="Top">
<Image ux:Name="visited" File="Assets/icon-up-arrow.png" Margin="10,0,10,0" Opacity="0" Height="40" Alignment="VerticalCenter" />
<StackPanel Alignment="VerticalCenter">
<Text Value="{title}" FontSize="18" Alignment="Center" Color="#000" />
<Text Value="{votes} votes - {market}" FontSize="12" Alignment="Center" Color="#c4c4c4" Margin="0,-3,0,10" />
</StackPanel>
<Image ux:Name="notVisited" File="Assets/icon-skip.png" Margin="10,0,10,0" Opacity="0" Height="40" Alignment="VerticalCenter" />
</Grid>
<Image ux:Name="notVisitedOverlay" StretchMode="UniformToFill" File="Assets/SkipOverlay.png" Opacity="0" Dock="Fill" />
<Image ux:Name="visitedOverlay" StretchMode="UniformToFill" File="Assets/VoteOverlay.png" Opacity="0" Dock="Fill" />
<Rectangle Dock="Fill">
<ImageFill Url="{image}" StretchMode="UniformToFill" WrapMode="ClampToEdge" />
</Rectangle>
<Grid Columns="1*,1,1*" Margin="0,0,0,0" Dock="Bottom" Height="55">
<StackPanel Padding="0,5,1,5" Margin="0,0,1,0">
<Text FontSize="12" Alignment="Center" Color="#000">SKIP! </Text>
<Text FontSize="12" Alignment="Center" Color="#c4c4c4">Swipe Left</Text>
</StackPanel>
<Rectangle Color="#e5e5e5" />
<StackPanel Padding="0,5,0,5">
<Text FontSize="12" Alignment="Center" Color="#000">VOTE UP!</Text>
<Text FontSize="12" Alignment="Center" Color="#c4c4c4">Swipe Right</Text>
</StackPanel>
</Grid>
</DockPanel>
<Rectangle Color="White" Margin="0" Height="100%" Width="100%">
<Shadow Distance="0" Size="2" ux:Name="shadow" />
</Rectangle>
<InForceFieldAnimation ForceField="visitedAttractor" From="0.1" To="0.3">
<Change visited.Opacity="1" Duration="1" />
<Change visitedOverlay.Opacity="1" Duration="1" />
</InForceFieldAnimation>
<!-- Add Vote -->
<EnteredForceField ForceField="visitedAttractor" Threshold="0.05" Handler="{addVote}">
</EnteredForceField>
<Draggable />
<WhileDragging>
<BringToFront />
<Scale Factor="1.1" Duration="0.5" Easing="BackOut" />
<Change shadow.Distance="20" Duration="0.5" Easing="BackOut" />
<Change shadow.Size="20" Duration="0.5" Easing="BackOut" />
</WhileDragging>
</Panel>
</Each>