Answered by:
How to use NameSpace to take values to next page

Question
-
I'm using Navigation App Template for one of my Win 8 app. I want to capture a value on homepage and then use it one next page. How do I do that ? My code is like below. It gives me value as undefined on the next page.
WinJS.UI.Pages.define(
"/pages/home/home.html", {
varopValue, opRangeValue;
varopValues = {
opSign: opValue,
opRangeVal: opRangeValue
};
// read opValue and opRangeValue from html elements and assign to opSing and OpRangeVal.
WinJS.Namespace.define(
"OperationValues", opValues);
}
On page2.js I'm trying to read that value:
WinJS.UI.Pages.define(
"/pages/practice/practice.html", {
ready:
function(element, options) {
// TODO: Initialize the page here.
console.log(
"OP :"+ OperationValues.opSign); // this gives op : undefined.
},
How do I do it without having any global variables?
Thanks
sonal
- Edited by SonalMac Wednesday, February 12, 2014 7:44 PM added a comment
Wednesday, February 12, 2014 7:42 PM
Answers
-
Hi Sonal,
Why not use: WinJS.Navigation.navigate("/pages/secondpage.html", yourvalue)? Then in your second page, you could receive the value by "options" in ready function. Take a look at the documentation: navigate function
And while reading the data, I think OperationValues is enough, OperationValues.opSign will definitely give a undefined result.
console.log( "OP :"+ OperationValues); // this should be ok. },
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Edited by Jamles HezModerator Thursday, February 13, 2014 1:46 AM
- Marked as answer by SonalMac Thursday, February 13, 2014 9:17 PM
Thursday, February 13, 2014 1:42 AMModerator
All replies
-
Hi Sonal,
Why not use: WinJS.Navigation.navigate("/pages/secondpage.html", yourvalue)? Then in your second page, you could receive the value by "options" in ready function. Take a look at the documentation: navigate function
And while reading the data, I think OperationValues is enough, OperationValues.opSign will definitely give a undefined result.
console.log( "OP :"+ OperationValues); // this should be ok. },
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Edited by Jamles HezModerator Thursday, February 13, 2014 1:46 AM
- Marked as answer by SonalMac Thursday, February 13, 2014 9:17 PM
Thursday, February 13, 2014 1:42 AMModerator -
Thanks. I got it.
sonal
Thursday, February 13, 2014 9:17 PM