I am passing in a jQuery object into a function from another file via an array like the following:
$(document).bind("loadStoreDisplayCallGoals", function(source, urlParams)
{
var selectedStoreDocument = urlParams["storeDocument"];
}
selectedStoreDocument
should be a jQuery object, however Visual Studio Intellisense will never recognize it as such. I tried adding extending selectedStoreDocument
with $.extend
:
// cast selectedStoreDocument to a jQuery type
$.extend(selectedStoreDocument, $);
However, extending selectedStoreDocument
wiped out all of my jQuery methods (.each
, .find
, etc.).
How can I get selectedStoreDocument
to appear as a jQuery object in IntelliSense? Note that I am working in Visual Studio 2010.
In Visual Studio, we get IntelliSense support for JavaScript in our markup files ( .html or .aspx) when we include these references using the <script> tag. But what if we are writing pure JavaScript ( .js) files which will later be included in our markups.
VS Code IntelliSense features are powered by a language service. A language service provides intelligent code completions based on language semantics and an analysis of your source code. If a language service knows possible completions, the IntelliSense suggestions will pop up as you type.
If not, XrmToolkit will re/generate them using the older format. XrmToolkit provides both JavaScript and TypeScript files that allow you to have all the intellisense features in Visual Studio for your CRM forms. To learn how to generate these files see the documentation found here .
Older versions of Visual Studio (prior to VS 2015) didn't have a separate folder and dumped that same information into files in the solution's root folder. In these older versions you can fix Intellisense issues by deleting the Solution's .suo file.
I created a separate file for utility functions, and a second file for the utility functions + VSDoc.
utilities.js:
function castToJQuery(item)
{
return item;
}
utilities-vsdoc.js:
function castToJQuery(item)
{
/// <summary>
/// 1: $(item) - "Casts" the specified item to a jQuery object for the sake of Intellisense
/// </summary>
/// <returns type="jQuery" />
return $("dummy");
}
Now I can call castToJQuery in any of my downstream files to make Visual Studio think a dynamic property is a jQuery object.
var selectedStoreDocument = castToJQuery(urlParams["storeDocument"]);
selectedStoreDocument.find("products");
Visual Studio now works with Intellisense for my dynamic urlParams["storeDocument"].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With