简体   繁体   English

Visual Studio 2010 Javascript Intellisense无法正常工作

[英]Visual Studio 2010 Javascript Intellisense not working properly

There's a little problem with Visual Studio 2010 and Javascript Intellisense. Visual Studio 2010和Javascript Intellisense有点问题。

I've implemented a class with some "Properties" and want to implement a "static" function, which returns a new instance of the class after an ajax-request which returns a Json-Object. 我已经实现了一个带有“属性”的类,并希望实现一个“静态”函数,该函数在ajax请求返回Json对象之后返回该类的新实例。

Like so: 像这样:

/// <reference path="jQuery/jquery-1.4.1-vsdoc.js" />
MyClass = function (options) {
    /// <summary>MyClass Description</summary>
    /// <param name="options" type="Array">Foo1 (string), Foo2(string)</param>
    /// <field name="Foo1" type="String">Foo1 Description</field>
    /// <field name="Foo2" type="String">Foo2 Description</field>

    // [...] Some Code

    // Properties
    this.Foo1 = options.Foo1;
    this.Foo2 = options.Foo2;
}

And the function: 和功能:

intellisense not working: 智能感知不起作用:

MyClass.MyFunction = function () { 
    /// <summary>MyFunction Description</summary>
    /// <returns type="MyClass">MyClass</returns>

    $.ajax({
        type: 'GET',
        url: '/Foo/Bar',
        dataType: 'json',
        success: function (result) {
            return new MyClass(result);
        }
    });
}

intellisense working: 智能工作:

MyClass.MyFunction = function () { 
    /// <summary>MyFunction Description</summary>
    /// <returns type="MyClass">MyClass</returns>

    var foo = new MyClass({'foo1': 'a', 'foo2': 'b'});
    $.ajax({
        type: 'GET',
        url: '/Foo/Bar',
        dataType: 'json',
        success: function (result) {
            foo = new MyClass(result);
            return foo;
        }
    });

    return foo;
}

When I call the function from another function, like: 当我从另一个函数调用该函数时,例如:

$(document).ready(function() {
    var foobar = MyClass.MyFunction(); // returns Object of type "MyClass"
    alert(foobar.Foo1); // At this Point, the intellisense doesn't work correct
});

my intellisense isn't working anymore (or works with the double-return), because the return of MyFunction is within the ajax-request. 我的智能不再起作用了(或不能使用两次返回),因为MyFunction的返回在ajax请求内。 If I place the return at the end of the function, the intellisense is working again. 如果我将return放在函数的末尾,则intellisense再次起作用。 But in this case I have two returns. 但是在这种情况下,我有两个回报。 The first from the function and the second from the ajax-success. 第一个来自函数,第二个来自ajax成功。

It seems that the <returns...></returns> only works when the return is at the end of the function. 看来<returns...></returns>仅在return在函数末尾时才起作用。 That's bad, because I just need one return when the ajax-request is completed. 不好,因为在ajax请求完成后,我只需要返回一个即可。

I don't know how to deal with this problem. 我不知道该如何处理。 Hope you can help me to fix this :) 希望你能帮我解决这个问题:)

The return from inside the "success" callback is not going to work anyway. 无论如何,从“成功”回调内部return将无法正常工作。 It'll return from that function, but nothing is going to pay attention to the return value, and in particular the return value from the "success" function will not be the return value from "MyFunction". 它将从函数返回,但是没有什么要注意返回值,尤其是“成功”函数的返回值将不是 “ MyFunction”的返回值。

If what you want is for "MyFunction" to fetch a value and allow some code to work on it, then that code will have to be passed in to "MyFunction" and called in the "success" function. 如果您要“ MyFunction”获取值并允许一些代码在其上工作,则必须将该代码传递给“ MyFunction”并在“成功”函数中调用。 Thus, instead of: 因此,代替:

var thing = MyClass.MyFunction();
/*
  do stuff with "thing"
*/

you'd change "MyFunction" around so that you could do this: 您可以更改“ MyFunction”,以便执行以下操作:

MyClass.MyFunction(function(thing) {
  /*
    do stuff with "thing"
  */
});

The function would look something like this: 该函数将如下所示:

MyClass.MyFunction = function (doStuff) { 
  /// <summary>MyFunction Description</summary>

  $.ajax({
    type: 'GET',
    url: '/Foo/Bar',
    dataType: 'json',
    success: function (result) {
        doStuff(new MyClass(result));
    }
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JavaScript 的 Visual Studio Code 自动完成/IntelliSense 无法正常工作 - Visual Studio Code autocomplete/IntelliSense not working properly for JavaScript Visual Studio 2010中缺少javascript intellisense - Lack of javascript intellisense in Visual Studio 2010 Visual Studio 2010中的LOCAL变量的Javascript Intellisense - Javascript Intellisense for LOCAL variables in Visual Studio 2010 Javascript Intellisense无法在Visual Studio 2010 Ultimate(Windows 7 x64)上运行 - Javascript Intellisense not working on Visual Studio 2010 Ultimate (Windows 7 x64) Visual Studio 2012 JavaScript智能感知不起作用 - Visual Studio 2012 JavaScript Intellisense Not Working Javascript Visual Studio Intellisense不能在一个项目上工作 - Javascript Visual Studio Intellisense Not Working On One Project Visual Studio 2022 智能感知不适用于 javascript - Visual studio 2022 intellisense not working on javascript Visual Studio中的JavaScript智能感知仅部分起作用 - JavaScript intellisense in Visual Studio only partially working JavaScript Intellisense在Visual Studio 2015中不起作用 - JavaScript Intellisense is not working in Visual Studio 2015 Visual Studio Code Intellisense 不适用于 Javascript - Visual Studio Code Intellisense not working for Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM