【发布时间】:2014-02-17 16:24:34
【问题描述】:
更新:请参阅下面的自我回答,其中说,这是一个 Visual Studio javascript intellisense 问题,需要“参考路径”解决方案,并提供了具体解决方案。最初的问题导致了错误的方向。
=======下面的原始问题============================
我已经构建了以下内容来存储和检索 VS2013 MVC 视图中不同窗格的高度和宽度值。 PaneDims 包含 pconfig 对象的数组 (pncnfgar)。我想使用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 之后,然后在另一个脚本文件中,当我尝试在SetInitialPanelDims() 中调用 PaneDims 时,
//================================
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];
}
}
}
【问题讨论】:
-
尝试将字段放在函数原型上。
-
我试过你的代码,它正在工作......
-
那么所有这些长代码块和长解释,这是一个 Intellisense 输入完成问题,而不是一个 javascript 语言问题?
-
@jfriend - 也许,我不知道。
-
@Toni,谢谢,这有助于澄清。另一个变量... SetInitialPanelDims 提供 .如果函数在同一个脚本文件中,则引用,但如果在单独的脚本文件中,则不引用。所以,那么问题是(我将其编辑为一个单独的脚本文件)。
标签: javascript visual-studio-2013 code-assist