11-09-2012 05:30 AM
Hi,
How do we retrieve the data passed in bb.pushScreen on another page.
When i do bb.pushScreen('js/mylibs/templates/synopsis.html',
What should i do in synopsis.html to get the parameters?
Please help.
Regards,
Annuk
11-09-2012 08:37 AM
1. I created a variable in the main index.html, before the bb.init code.
2. I then dynamically create a page that lists my data and sets the var (from a database)
listItem.setAttribute('onclick', 'fs_id = "' + itemKey + '";
3. Clicking on the link will set the var and push the page.
4. The new page will check the var and apply any needed code.
I guess for a simple app you could do:
onclick="myVar=myParam;bb.pushScreen('myhtmlpage.h tml', 'myhtmlid');"
myVar would need to be declared in the index.html...
11-12-2012 05:03 PM
hi annuk,
This is documented in the "Screens" page within the bbUI wiki site:
https://github.com/blackberry/bbUI.js/wiki/Screens
"This third optional parameter will then be passed into the onscreenready and ondomready events (provided in the toolkit initialization) when they fire for the associated screen"
So you'll need to establish a handler for the onscreenready and ondomready events. Details here:
https://github.com/blackberry/bbUI.js/wiki/Toolkit
12-11-2012 06:33 AM
Hi astanley,
Thanks for your reply. Did as you said. I want to retrieve the passed parameter in another html. How do I retrieve it? I added a javascript function for setting the value of the parameter.
My code:index.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SAMPLE</title>
<meta name="x-blackberry-defaultHoverEffect" content="false" />
<link rel="stylesheet" type="text/css" href="bbui-0.9.4.css">
<link />
<script type="text/javascript" src="bbui-0.9.4.js"></script>
<script type="text/javascript" src="js/webworks-1.0.2.9.js"></script>
<script type="text/javascript">
document.addEventListener('webworksready', function(e) {
// For some fun I did some random color scheme generation :o)
var highlightColor, randomNumber;
randomNumber = Math.floor(Math.random() * 100);
if (randomNumber > 90) {
highlightColor = '#BA55D3';
} else if (randomNumber > 60) {
highlightColor = '#00BC9F';
} else if (randomNumber > 30) {
highlightColor = '#00A8DF';
} else {
highlightColor = '#B2CC00';
}
// You must call init on bbUI before any other code loads.
// If you want default functionality simply don't pass any parameters.. bb.init();
bb.init({
actionBarDark : true,
controlsDark : true,
listsDark : false,
bb10ForPlayBook : false,
highlightColor : highlightColor,
// Fires "before" styling is applied and "before" the screen is inserted in the DOM
onscreenready : function(element, id,param) {
if (id == 'dataOnLoad') {
dataOnLoad_initialLoad(element);
} else if (id == 'masterDetail') {
masterDetail_initialLoad(element);
}
// Remove all titles "except" input and pill buttons screen if running on BB10
if (bb.device.isBB10 && (id != 'input') && (id != 'pillButtons')) {
var titles = element.querySelectorAll('[data-bb-type=title]');
if (titles.length > 0) {
titles[0].parentNode.removeChild(titles[0]);
}
}
if (id == 'sample') {
console.log('id is sample in onscreenready');
if (param != null) {
//alert(param.name);
addData(element, param);
}
}
},
// Fires "after" styling is applied and "after" the screen is inserted in the DOM
ondomready : function(element, id) {
if (id == 'dataOnTheFly') {
alert('Data on the fly');
}
}
});
bb.pushScreen('sample.html', 'sample',{'name':'annuk'});
}, false);
</script>
</head>
</html>
The index.html calls the onScreenReady function twice.
I get the logs twice.
Logs:
Ripple :: Environment Warming Up (Tea. Earl Gray. Hot.) ripple.js:475 webworks.bb10 :: Initialization Finished (Make it so.) ripple.js:475 id is sample in onscreenready index.html:51 in sample.js addData [object Object] browse.js:23 value is [object Object] browse.js:25 webworks.bb10 :: fired webworksready event! ripple.js:475 id is sample in onscreenready index.html:51 in sample.js addData [object Object] browse.js:23 value is [object Object]
My js file:
var value;
function addData(element, param) {
console.log('in sample.js addData ' + param);
this.value = param;
console.log('value is '+value);
}
function getData() {
console.log('in sample.js getData ' + this.value);
return this.value;
}
How do I retreive it in sample.html? Where am i going wrong?
Regards,
Annuk