Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Trusted Contributor
Posts: 100
Registered: ‎03-31-2012
My Device: Blackberry 9780
My Carrier: Telkomsel

[Help] Convert jQuery Code

[ Edited ]

I want to make my connection to the database server using jquery. But I wonder how can I modify the example code from my jquery into bbui rules.

My code : http://pastebin.com/LfGCPU7D

I want to make it work well as examples of self BBUI : http://pastebin.com/VgsKRz4N

 

I use the sample : Load Data After Showing (dataOnTheFly.htm)

Regards,
Bertho
Developer
Developer
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: [Help] Convert jQuery Code

Hi bertho.

 

First of all, if you want to do, you need to rewrite the ajax call to use the plain XMLHttpRequest. Some nice examples are available here: https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest

 

For the dataList elements you should have a closer look to the bbUI.js wiki page for the image-lists. I think there are enough samples to get started!!

 

If the ajax call and the response/success functionality is all you are using jQuery for I would recommend to not use it since using a "big" (in size) framework like jQuery for only some calls/use cases doesn't make any sence for me.


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Trusted Contributor
Posts: 100
Registered: ‎03-31-2012
My Device: Blackberry 9780
My Carrier: Telkomsel

Re: [Help] Convert jQuery Code

I happen to use jquery because it has been accustomed to use it .. Smiley Happy
Should not be used because it would incriminate the UI in BB itself?

Regards,
Bertho
Developer
Developer
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: [Help] Convert jQuery Code

As far as I know there are some issue when using frameworks, but I think Tim from RIM will fix those things if he knows. I, by myself do not use frameworks if I only need to do some small things that can be done with some lines of code I wrote myself and also I understand since this might be essential when debugging, to understand the used code.

 

For your example I think you can go on using the jQuery Ajax source if you want to but for bbUI.js image-list you need to go deeper into bbUI functionality. I also think it should be that much to be done to get it working, but it would be good to know how it should look like.


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: [Help] Convert jQuery Code

The trick to manipulating the UI in your bbUI application is understanding the onscreenready and ondomready events.  If you are looking to manipulate the screen using jQuery selectors $('mydiv') then you must wait until the ondomready event fires so that your screen is in the live document

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Trusted Contributor
Posts: 100
Registered: ‎03-31-2012
My Device: Blackberry 9780
My Carrier: Telkomsel

Re: [Help] Convert jQuery Code

Do you mean $(document).ready(function() ?

 

Regards,
Bertho
Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: [Help] Convert jQuery Code

No.. the bbUI.js ondomready function that will fire for each screen you load

 

https://github.com/blackberry/bbUI.js/wiki/Toolkit-Initialization

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Trusted Contributor
Posts: 100
Registered: ‎03-31-2012
My Device: Blackberry 9780
My Carrier: Telkomsel

Re: [Help] Convert jQuery Code

Is bb.init function should always be placed on each page?
Or just put on index.htm as in the example of your page?

 

Will I still be able to use the $. Ajax as my example, or have to adjust to the style of your example?

Regards,
Bertho
Developer
Developer
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: [Help] Convert jQuery Code

You only need to init bbUI one time on the index.html (or whatever is configured in your config.xml). Within the bb.init(...) you define what to do ondomready and onscreenready. With bbUI.js you also easily switch between screens, not complete pages.

 

Since you want to use jQuery, I think this is what Tim mentioned before, your source code needs to be called in bbUI's ondomready handler in the bb.init(..).

 

Have a closer look to the repo sample of the index.htm at line 64: https://github.com/blackberry/bbUI.js/blob/master/samples/index.htm#L64

At this time the DOM is ready, so you could use jQuery directly to run your source code. I think to make it working as a sample and to understand how it works add your source within the "dataOnTheFly_initialLoad" function in the dataOnTheFly.js file from the bbUI.js samples and see what happens.


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Trusted Contributor
Posts: 100
Registered: ‎03-31-2012
My Device: Blackberry 9780
My Carrier: Telkomsel

Re: [Help] Convert jQuery Code

[ Edited ]

Please checked and notified to my mistakes. This is an example of code that I created.

 

index.html :

http://pastebin.com/Kun6BSs6

 

menu.html :

http://pastebin.com/BeVqT0w8

 

javascript  :

http://pastebin.com/VvJxWv0W

 

MySamplePage.html :

http://pastebin.com/c2cmh3AB

 

I think I've done well.
Maybe you could check if I ask and I'm doing is right or not

Regards,
Bertho