我有一段代码如下。
var aMessages = new Array();
aMessages["gender"] = new Array();
aMessages["gender"]["blank"] = new Array();
aMessages["gender"]["blank"]["Default"] = "Please select the gender of the person being registered on the site.";
aMessages["gender"]["blank"]["Self"] = "Please select your gender.";
aMessages["gender"]["blank"]["Son"] = "Gender of the member is required for registration.";
aMessages["gender"]["blank"]["Daughter"] = "Gender of the member is required for registration.";
aMessages["gender"]["blank"]["Brother"] = "Gender of the member is required for registration.";
aMessages["gender"]["blank"]["Sister"] = "Gender of the member is required for registration.";
aMessages["gender"]["blank"]["Friend"] = "Please select your friend's gender.";
aMessages["gender"]["blank"]["Relative"] = "Please select your relative's gender.";
aMessages["gender"]["invalid"] = "Please choose relevant gender.";
function displayMessage(field, errorCase){
console.log(errorCase, field, "here");
console.log(aMessages[field][errorCase]);
}
err = 'invalid';
displayMessage("gender", err);
所以我将字段和错误案例传递给函数,函数做一些事情,现在假设它打印消息。对于一个级别来说很好,即gender (field) -> err (errorcase)
。但是如何在参数中传递索引的索引。
是否有任何解决方法。还建议任何其他好的方法。