08-12-2012 10:55 PM
I have developing a new app that use bbui.js, minpubsub.js and jquery, and now I got a very strange issue, please help.
in the init function, I use minpubsub to publish onscreenready&ondomready events like this:
bb.init({
bb10ActionBarDark: true,
bb10ControlsDark: true,
bb10ListsDark: false,
onscreenready:function (element, id) {
publish("/Views/" + id + "/beforeShow",[element,id]);
},
ondomready:function (element, id) {
publish("/Views/" + id + "/afterShow",[element,id]);
}
});
then I use minpubsub's subscribe function to process the event, if I write the code like this:
subscribe("/Views/mainPage/beforeShow",function(el
loadItemToMainPage(element);
});
in the loadItemToMainPage function, I use the element argument to modify the page, like this,
var title = element.getElementById("maintitle");
title.setCaption(userEmail);
but this does not work, I got this error message:
Uncaught TypeError: Object #<HTMLDivElement> has no method 'setCaption'
but if I wrote code like this:
subscribe("/Views/mainPage/afterShow",function(ele
loadItemToMainPage(document);
});
this code runs successfully.
the second issue:
the loadItemToMainPage function will load some data into image list, and if use click an item, the app will show detail page that show detailed message, but if I put the loadItemToMainPage function in:
subscribe("/Views/mainPage/afterShow",function(ele
loadItemToMainPage(document);
});
and if use click detail page's back button on the actionbar, image list in the main page will be blank.
08-13-2012 02:09 AM
Please use the "Insert Code" button the add more readability to the post.
For your questions:
Are you using the
title.setCaption(...);
when the onscreenready event is fired from the bbUI.JS or ondomready? onscreenready doesn't work since this function is only available after bbUI.js has assigned the style for elements to your screen you inserting.
Have a closer look to the example for bbUI.js Buttons, the setCaption function is used in this way:
document.getElementById('plainBtn').setCaption('my caption');
so the document (DOM) needs to be ready, so you can use it earliest when the ondomready was fired.
Or you use another way to get it working onscreenready. You can apply the layout for whatever you have at this time when you use something like in the bbUI.js "ondom" function is called. There are a lot of things in there, for example if you want to add the image-list layout at this time you could use:
bb.imageList.apply([imageListRootElement]);
or for a button use:
bb.button.apply([buttonElement]);
BTW: why you are using "publish-before" and "publish-after" when you are able to do such things using the plain onscreenready and ondomready events together with the "element", where the "element" is your screen to be inserted? I think your code could be much simpler without minpubsub and I can't see why it would be helpful to use minpubsub for your use case.