我有一个包含各种通知的数组,其中包括各自的标题和说明。我希望通过标题访问某个通知,但我似乎无法在数组中找到匹配项,即使它应该存在。
NotificationMenu = function()
{
var NotificationItems = new Array();
this.Application = function(title, description, functionName)
{
this.mTitle = title;
this.mDescription = description;
this.mFunction = functionName;
this.mIsActive = true;
}
this.registerNotification = function(title, description, functionName)
{
NotificationItems.push(new this.Application(title, description, functionName));
}
this.activateNotification = function(title)
{
console.log("-NotificationMenu: Activating notification " + title);
// Check through the list of notifications for the one called to be shown
for(var i = 0; i < NotificationItems.length; ++i)
{
if (NotificationItems[i].mName === title)
{
// This is never getting called
console.log("-NotificationMenu: Successful entry");
}
}
}
}
我访问数组的方式有什么问题,以至于无法匹配两个游戏?特别是,行if(NotificationItems[i].mName === title)
永远不会返回true
。
答案 0 :(得分:6)
mName
构造函数中没有定义Application()
。也许你的意思是使用mTitle
:
if (NotificationItems[i].mTitle === title)