model is undefined on document ready

I am trying to get the current loaded model id in my document ready method.

(function(skuid) { var $ = skuid.$; var params = arguments[0]; var activateHandler = function() { skuid.$(“#bodyTable .nx-conditioncontainer-left .nx-conditiontoken.nx-actionselect .nx-actionselect-arrow”).on(“click”, function() { setTimeout(function() { skuid.$(“#bodyTable .nx-conditioncontainer-left .nx-actionselect-dropdown .nx-actionselect-dropdown-item”).on(“click”, function() { if (this.innerHTML === ‘** All Years’) { console.log(‘All Years’); console.log(params.model.id); } }); }) }); }; $(document.body).one(‘pageload’, activateHandler); skuid.events.subscribe(“models.loaded”, activateHandler); })(skuid);

Hi Prateek, “params.model.id” is the issue here, params.model will never be defined in this scenario. Since you are already hard-coding the name of the table element (#bodyTable), you could just hard-code the name of the Model Id as well, and access it using skuid.model.getModel(modelId):

console.log(‘All Years’);
var myModelId = “AllYearsModel”;
var myModel = skuid.model.getModel(myModelId);
console.log(myModel.id);

If you are trying to get the id of the model dynamically from the DOM, you could access it from a table instance like this:

var tableModel = skuid.$(“#bodyTable”).data(“object”).model;
console.log(“Table’s model id: " + tableModel.id”);

Hi Zach,
I tied to get the modal id dynamically but I am still getting the error as undefined. The use case of this logic is to after executing the below line code

$(document.body).one

I want to get the currently loaded model id dynamically, so that I can modify something with the currently loaded model, not with the other tabsets.

Please let me know your expert suggestions to solve this issue.

Prateek, I am not sure what you mean by “currently loaded” model. I would modify your code to something like this:

(function(skuid) {<br />&nbsp; &nbsp; var $ = skuid&#46;$;<br />&nbsp; &nbsp; var activateHandler = function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; skuid&#46;$("#bodyTable &#46;nx-conditioncontainer-left &#46;nx-conditiontoken&#46;nx-actionselect &#46;nx-actionselect-arrow")&#46;on("click", function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setTimeout(function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; skuid&#46;$("#bodyTable &#46;nx-conditioncontainer-left &#46;nx-actionselect-dropdown &#46;nx-actionselect-dropdown-item")&#46;on("click", function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (this&#46;innerHTML === '** All Years')<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console&#46;log('All Years');<br /><b>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var modelId = $(this)&#46;closest("&#46;nx-skootable")&#46;data("object")&#46;model&#46;id</b><br /><b>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console&#46;log("Model Id: " + modelId);</b><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })<br />&nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; };<br />&nbsp; &nbsp; $(document&#46;body)&#46;one('pageload', activateHandler);<br />&nbsp; &nbsp; skuid&#46;events&#46;subscribe("models&#46;loaded", activateHandler);<br />})(skuid);

Thanks a lot Zach, it worked for me.