Skip to main content

Is this possible? In a static resource JS file, when I try something like this: var taskModel = skuid.model.getModel(‘MimeoTask’); var task = taskModel.getFirstRow(); I get the error: Uncaught TypeError: Cannot call method ‘getFirstRow’ of undefined Obviously this code is executing before the model has loaded up, so is there a callback or hook I can attach my code to? I know I can get it to work if I wrap it in a component. Just wondering if it is possible to do without a component, and why there is no documentation of this? The example at the bottom of the Model API reference: Page Not Found — Skuid v15.1.6 Documentation makes it seem like this should work.

Good question, and you’re right, we should add documentation to help describe this. The answer is, yes it is possible to do without a component. The trick is to run this in a jQuery ready callback so that it won’t get run until all Models have been loaded, and all Components on the page have been built. You can do this by adjusting your JS code to be something like this:


(function(skuid){ skuid.$(function(){ var taskModel = skuid.model.getModel('MimeoTask'); var task = taskModel.getFirstRow(); }); })(skuid); 

Really you could just do this:


skuid.$(function(){ var taskModel = skuid.model.getModel('MimeoTask'); var task = taskModel.getFirstRow(); }); 

but we wrap the code in a closure just to make sure there are no conflicts with global variables. skuid.$ is just a reference to the jQuery version that Skuid uses.


I noticed that it worked if I put it inside the $.ready callback, but I wasn’t sure if this was a timing thing and would be unreliable or if the model was guaranteed to be available at this point. Thanks for the quick reply.


Reply