我通过以下数组将jQuery对象传递到另一个文件的函数中:
$(document).bind("loadStoreDisplayCallGoals", function(source, urlParams)
{
var selectedStoreDocument = urlParams["storeDocument"];
}
selectedStoreDocument
应该是一个jQuery对象,但Visual Studio Intellisense永远不会识别它。我尝试使用selectedStoreDocument
添加扩展$.extend
:
// cast selectedStoreDocument to a jQuery type
$.extend(selectedStoreDocument, $);
但是,扩展selectedStoreDocument
会消除我的所有jQuery方法(.each
,.find
等)。
如何让selectedStoreDocument
在IntelliSense中显示为jQuery对象?请注意,我在Visual Studio 2010中工作。
答案 0 :(得分:6)
我为实用程序函数创建了一个单独的文件,为实用程序函数+ VSDoc创建了第二个文件。
utilities.js:
function castToJQuery(item)
{
return item;
}
公用事业-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");
}
现在我可以在任何下游文件中调用castToJQuery,以使Visual Studio认为动态属性是一个jQuery对象。
var selectedStoreDocument = castToJQuery(urlParams["storeDocument"]);
selectedStoreDocument.find("products");
Visual Studio现在可以与Intellisense一起使用我的动态urlParams [“storeDocument”]。
答案 1 :(得分:2)
您无法获得动态添加属性的智能感知功能。您需要静态定义它们(在vsdoc或js文件中):
$.selectedStoreDocument = function() {
///<summary>A Selected Store Document</summary>
};
答案 2 :(得分:1)
您可以为此变量指定文档信息:
$(document).bind("loadStoreDisplayCallGoals", function(source, urlParams)
{
/// <var type="jQuery"/>
var selectedStoreDocument = urlParams["storeDocument"];
selectedStoreDocument._
}
有关详细信息,请参阅http://msdn.microsoft.com/EN-US/library/hh542722(VS.110).aspx