PDA

View Full Version : Load external java script files for an "item"



preyz
25 Mar 2011, 8:50 AM
I would like to load parts of my code from different script files, to make individual files easier to work in. I've tried the approach from the "kitchensink" examples, where the code shows:



// Top of index.js
Ext.ns('sink', 'demos', 'Ext.ux');

// Items array loaded later on...
items: [
{
text: 'Buttons',
card: demos.Buttons,
source: 'src/demos/buttons.js',
leaf: true
},

Now, if I do the same thing, it doesn't work for my application! I don't get any errors, and my alert() in the external files isn't executed. So I believe my external javascript file isn't being loaded at all.

Does anyone have suggestions, or maybe even a working example of how to load external script files?

backwardsTraveller
25 Mar 2011, 8:37 PM
I'm sure this topic has been discussed Ad nauseam on this board, but I'm also stuck at this concept. Except, I'm trying to invoke an external js file(well, a module within that file) when a bottom toolbar item is clicked. Can anyone recommend a good tutorial for explaining this?

preyz - If you're not even getting an alert you may have not actually included the external javascript file in your index.html. Notice the kitchensink's index.html includes all the files.
Also, I may be wrong on this, but the "source" column referenced in your snippet isn't an actual Sencha value. It's from the Demo model defined in structure.js. Unless you're passing in a record that is an element of a store defined by that model, those values won't mean anything. The magic you're looking for is probably around line 154 in that index.js. The setActive item is what will change to what has already been loaded in your external code.

preyz
16 Apr 2011, 10:27 AM
*sometimes I feel like running my heard right into a concrete wall - repeatedly*

c2c-shiner
18 Apr 2011, 11:28 AM
did you add src/demos/buttons.js to the index.html page?

preyz
19 Apr 2011, 2:21 AM
Yes, my previous post was an acknowledgement of this extremely embarrassing mistake... ;-)