i'm using nativescript to build a basic app but i'm stuck sending the context between pages.
I'm listing a serie of items in page1 that i get from an http request and what i want to achieve is send the id of the item into the context to make an http request and render the response in page2.
Here is my approach:
page1.xml (this page is injected into a tabviewitem)
<StackLayout class="tab-content" loaded="onViewLoaded">
<GridLayout rows="auto, *">
<ListView items="{{ motels }}"
row="1"
id="motelsList"
motelId="{{ id }}"
name="{{ name }}"
itemTap="goToMotelDetail">
<ListView.itemTemplate>
<GridLayout columns="auto, *">
<GridLayout columns="auto" rows="auto" class="icon-wrap">
<Image width="70" height="70" src="http://fpoimg.com/70x70" stretch="fill" css="icon-image" />
</GridLayout>
<StackLayout col="1" verticalAlignment="center">
<Label text="{{ name }}" textWrap="true" class="motel-name" />
<Label text="{{ address }}" textWrap="true" class="motel-address" />
</StackLayout>
</GridLayout>
</ListView.itemTemplate>
</ListView>
<ActivityIndicator busy="{{ isLoading }}" row="1" horizontalAlignment="center" />
</GridLayout>
</StackLayout>
page1.js
exports.goToMotelDetail = function(args) {
var id = args.object.motelId;
var name = args.object.name;
var navigationEntry = {
moduleName: "views/motel-detail/motel-detail",
context: {
info: "some string to test",
id: id,
name: name
},
animated: false
};
var topmost = frameModule.topmost();
topmost.navigate(navigationEntry);
}
page2.xml
<Page navigatedTo="navigatedTo">
<Page.ActionBar>
<ActionBar title="{{ name }}" />
</Page.ActionBar>
<Label text="Motel detail" />
</Page>
page2.js
exports.navigatedTo = function (args) {
var page = args.object;
var dataItem = page.navigationContext;
page.bindingContext = dataItem;
};
The thing is: when i click on an item the app navigate to page2, but doesn't show the name tha was sent within the context and if i try with info, it works.
I can't figure out how to make it work.
Thanks in advance