Hi
I am building an app much like the hikr tutorial where each hike is an instance of a javascript class containing an observable property and when I click on a certain hike I want to go to another page but still accessing the instance of the chosen hike.
Code-wise I want to do the following:
<App>
<JavaScript>
var Observable = require("FuseJS/Observable");
var Timer = require("FuseJS/Timer");
var allInstances = Observable();
function myClass() {
this.myProperty = Math.floor((Math.random() * 100) + 1);
this.myObservableProperty = Observable(0);
}
function addInstance() {
allInstances.add(new myClass());
}
Timer.create(function() {
allInstances.forEach(function(instance) {
instance.myObservableProperty.value += 1;
})
}, 1000, true);
function goToPage(instance) {
router.push("page2",instance.data);
}
module.exports = {
allInstances: allInstances,
addInstance: addInstance,
goToPage: goToPage
}
</JavaScript>
<Router ux:Name="router" />
<Navigator DefaultPath="page1">
<Page1 ux:Template="page1" router="router" />
<Page2 ux:Template="page2" router="router" />
</Navigator>
<Page ux:Class="Page1">
<Router ux:Dependency="router" />
<StackPanel>
<Button Text="Add an instance" Clicked="{addInstance}" />
<Each Items="{allInstances}">
<Text Value="{myProperty}" />
<Text Value="{myObservableProperty}" />
<Button Text="Go to page" Clicked="{goToPage}" />
</Each>
</StackPanel>
</Page>
<Page ux:Class="Page2">
<Router ux:Dependency="router" />
<JavaScript>
var passedInstance = this.Parameter;
module.exports = {
passedInstance: passedInstance
}
</JavaScript>
<Text Value="{passedInstance.myObservableProperty}" />
</Page>
</App>
I am not sure it is possible but does anyone have any idea of how it could be done?
Best regards
Morten