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

Native Development

Reply
Contributor
chanzdevilz
Posts: 16
Registered: ‎06-06-2011
My Device: 8520
Accepted Solution

add javascript library

hi all, i want add javascript library to my apps.  i tried https://developer.blackberry.com/native/documentation/cascades/dev/javascript/ dan http://qt-project.org/doc/qt-4.8/qdeclarativejavascript.html guide but it did't work.

 

Does anyboy have solution ?

 

Thanks.

Regular Contributor
coolneo
Posts: 56
Registered: ‎06-25-2012
My Device: non-blackberry user

Re: add javascript library

Hi,

 

Using JS in any QML app should be straight forward.

 

Can you let us know what error you are getting ?? I generally dont use the min version of the library but it should not be a problem.

 

Another guess would the library is using something very specific to some platform than that can be a problem !!

 

 

Contributor
chanzdevilz
Posts: 16
Registered: ‎06-06-2011
My Device: 8520

Re: add javascript library

When build i got 

Errors occurred during the build.
Errors running builder 'JavaScript Validator' on project 'Mindtalk'.
9

 But i already uncheck JavaScript semantic validation.

 

I tried to run application. It got an error , i just contine run application and it was working.

import "../../libs" as TimeFunctions

Contaner{
    property int time
    Label{
       text: TimeFunctions.moment([2013,10,9]).fromNow()
    }
}

 it got error : 'TimeFunctions.moment' [undefined] is not a function.. 

 

 

 

 

Retired
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30

Re: add javascript library

[ Edited ]

I don't think the import path will work. You'll be importing that file at run time, so the path will be relative to the app's directory at launch. Also, it looks like you are importing a folder instead of a specific file.

 

I'd try putting the js library in the same folder as your QML file to start and then just do something like

 

import "TimeFunctions.js" as TimeFunctions

 

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Contributor
chanzdevilz
Posts: 16
Registered: ‎06-06-2011
My Device: 8520

Re: add javascript library

i tried at same folder now it can call TimeFunctions. now

Warning: asset:///moment-with-langs.js:6822: Error: Invalid write to global property "moment"

 i tried moment-with-langs.js in html, it was working. Do you have an idea why? 

 

Thanks.

Retired
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30

Re: add javascript library

The JS engine in QML is a bit different from what you would find in a browser. For example, from the docs:

 

"In QML you cannot add, or modify, members of the JavaScript global object. It is possible to do this accidentally by using a variable without declaring it. In QML this will throw an exception, so all local variables should be explicitly declared."

 

That is probably what you are running in to.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Contributor
chanzdevilz
Posts: 16
Registered: ‎06-06-2011
My Device: 8520

Re: add javascript library

it means, i can not use that javascript library? Do you have another library to make datetime countdown ? for example : yesterday, one week ago.

Retired
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30

Re: add javascript library

Well, I can't really speak to that library since it's not ours. You could try fixing it. It could just be using an uninitialized variable.

 

What are you trying to do that isn't covered by the built in Date object?

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Contributor
chanzdevilz
Posts: 16
Registered: ‎06-06-2011
My Device: 8520

Re: add javascript library

Ok, Thanks for your help.