我想知道,我有这个数组,其中包含我需要的所有数据。我想要做的是选择StateCode 5,它显示名称值Awaiting Banking Details
这是数组布局。
var status = [
{StateCode:1, Name:"1st Email"},
{StateCode:2, Name:"1st Contact"},
{StateCode:4, Name:"2nd Email"},
{StateCode:3, Name:"Call Back"},
{StateCode:5, Name:"Awaiting Banking Details"},
{StateCode:6, Name:"Detail Form Emailed"},
{StateCode:7, Name:"Refused Banking Details"},
{StateCode:8, Name:"Signed Up Silver"},
{StateCode:9, Name:"Welcome Letter Emailed"},
{StateCode:10, Name:"Optimised on Web"},
{StateCode:11, Name:"Upgraded To Gold"},
{StateCode:12, Name:"Sent Upgrade Email"},
{StateCode:13, Name:"Upgraded to Platinum"},
{StateCode:14, Name:"Not Interested"}
];
最佳答案
您必须遍历对象,并检查其StatusCode
:
var value;
$.each(status, function(){
if (this.StateCode == 5) {
value = this.Name;
return false;
}
});
关于jquery - jQuery-获取数组值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7479456/