[英]Mimicking Casting with Visual Studio's JavaScript IntelliSense
我通過如下所示的數組將jQuery對象傳遞到另一個文件的函數中:
$(document).bind("loadStoreDisplayCallGoals", function(source, urlParams)
{
var selectedStoreDocument = urlParams["storeDocument"];
}
selectedStoreDocument
應該是一個jQuery對象,但Visual Studio Intellisense永遠不會識別它。 我嘗試使用$.extend
添加擴展的selectedStoreDocument
:
// cast selectedStoreDocument to a jQuery type
$.extend(selectedStoreDocument, $);
但是,擴展selectedStoreDocument
清除我的所有jQuery方法( .each
, .find
等)。
如何讓selectedStoreDocument
在IntelliSense中顯示為jQuery對象? 請注意,我在Visual Studio 2010中工作。
我為實用程序函數創建了一個單獨的文件,為實用程序函數+ 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”]。
您無法獲得動態添加屬性的智能感知。 您需要靜態定義它們(在vsdoc或js文件中):
$.selectedStoreDocument = function() {
///<summary>A Selected Store Document</summary>
};
您可以為此變量指定文檔信息:
$(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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.