Using setJavaScriptMember
Added by Edward Hill over 1 year ago
Hi,
I load javascript in widget through function setJavaScriptMember, but it's take a string, so is any possible load already prepared javascript file?
Replies
RE: Using setJavaScriptMember - Added by Koen Deforche over 1 year ago
Hey Edward,
No, not through the public API (we have a system within Wt that does this).
But you could implement this so that a widget reads one or more members from a file ?
Regards,
koen
RE: Using setJavaScriptMember - Added by Edward Hill over 1 year ago
Right now widget should read 4 JavaScript functions
RE: Using setJavaScriptMember - Added by Edward Hill over 1 year ago
So how can I load my own javascript code?
RE: Using setJavaScriptMember - Added by Koen Deforche over 1 year ago
Hey,
We have not implemented anything to specifically support this. My guess would be to build a simple parser which reads multiple functions from a JavaScript file and binds each of these using setJavaScriptMember().
That would make a nice reusable utility function which might be useful for the library:
bool bindJavaScriptMembers(WWidget *w, const std::string& fname);
and fname contains code like:
member m1 = function() { ... }
member m2 = function(arg1, arg2) { ... }
...
and the function bindJavaScriptMembers parses this file, skipping the function body by parsing JavaScript to the point that it can differentiate '{', '}', and string literals.
Regards,
koen