更新:请参阅下面的自我回答,其中说,这是一个 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];
}
}
}