0

更新:请参阅下面的自我回答,其中说,这是一个 Visual Studio javascript intellisense 问题,需要“参考路径”解决方案,并提供具体解决方案。最初的问题导致了错误的方向。

=======下面的原始问题============================

我已经构建了以下内容来存储和检索 VS2013 MVC 视图中不同窗格的高度和宽度值。 PaneDims包含一个对象数组 ( pncnfgar) pconfig。我想PaneDims用作全局可用的对象,我可以访问使用"."符号的方法和参数,例如PaneDims.getconfig. 我想pconfig用作一个可实例化的对象,我可以从中填充PaneDims.getconfig,然后还可以访问使用"."符号的参数,例如。wrk_pconfig.id.

//=========================

var pconfig = function () {
this.id = ""
this.mh = 0
this.mw = 0
this.lh = 0
this.lw = 0
this.dh = 0
this.dw = 0
}
//========================================
var PaneDims = new function () {
this.currPaneConfig = "";
this.pcnfgar = [];
this.getconfig = function (id) {
    for (i = 0; i < this.pcnfgar.length; i++) {
        if (this.pcnfgar[i].id === id) {
            return this.pcnfgar[i];
        }
    }
}
}
//===================================
function TestPaneDims() {
CreatePaneDimsClass()
SetInitialPanelDims()
}
//====================================
function CreatePaneDimsClass() {
//var PaneDims = new PaneDims;
LoadPanelConfigs();
}
//===========================================

我省略了细节,LoadPanelConfigs因为这一切都有效,这不是问题。

问题是在我运行之后CreatePaneDimsClass,然后在另一个脚本文件中,当我尝试调用 PaneDims 时SetInitialPanelDims()

//================================
function SetInitialPanelDims() {

    PaneDims.currPaneConfig = "dh1w1"
    wrkpc = new pconfig
    wrkpc = PaneDims.getconfig(PaneDims.currPaneConfig)

    b = wrkpc.id
    d = wrkpc.mh
    d = wrkpc.mw
}
//===============================

同样,从处理的角度来看,这一切都有效。

问题是,当我编写代码时,"."值不会出现。例如我在打字

b = wrkpc.

我想看到一个pconfig可供选择的参数列表。

那么,我误认为这是可能的(在 C# 中吃了太多的智能感知)?或者我需要做些什么才能让我想要的事情发生?

更新:.如果SetInitialPanelDims函数与其他代码位于同一脚本文件中,则引用有效,但如果它位于不同的脚本文件中,则引用无效。

那么,如果在单独的脚本文件中调用该函数,我如何使.引用工作?PaneDims

更新:尝试PaneDims使用原型和实例化创建;可以正常处理,但不能解决代码编写问题

function pPaneDims() { }
pPaneDims.prototype.pcnfgar = [];
pPaneDims.prototype.currPaneConfig;
pPaneDims.prototype.getconfig = function (id) {
    for (i = 0; i < this.pcnfgar.length; i++) {
        if (this.pcnfgar[i].id === id) {
            return this.pcnfgar[i];
        }
    }
}
4

1 回答 1

0

这似乎是一个 Visual Studio javascript intellisense 问题,需要“参考路径”解决方案。也就是说,要添加这样的注释行(三个正斜杠):

/// <reference path="~/Scripts/020_DRAFT/MyScript.js" />

在您希望智能感知访问 MyScript.js 中的内容的 JS 文件的顶部。

触发线索就在这里。

Javascript 和 VS2012 智能感知

我不明白“将一个 JavaScript 文件拖到另一个文件上”是什么意思,但仅仅编写引用语句就可以了。

让我想起了 C# 中的“使用”语句。

如何在 VS2010 中为 javascript IntelliSense 引用多个文件

http://msdn.microsoft.com/en-us/library/bb385682.aspx

http://gurustop.net/blog/2012/03/03/javascript-js-intellisense-auto_complete-in-visual-studio-11-beta-the-web-_references-js-file/

这使得这个问题或多或少与最初的措辞无关。

于 2014-01-28T02:02:48.627 回答