【发布时间】:2015-01-23 15:17:30
【问题描述】:
我想要一个抽象方法根据我作为参数传递给方法的属性名来读取json对象的属性。
我认为举个例子更容易解释。
假设我有以下 json 对象:
var coll =
[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
function GetPropertyValue(collection, index, property_name)
{
:
:
}
在哪里
GetPropertyValue(coll, 0, 'firstName');
返回“约翰”,而
GetPropertyValue(coll, 0, 'lastName');
返回“Doe,并且
GetPropertyValue(coll, 2, 'lastName');
返回“琼斯”
问候。
【问题讨论】:
标签: jquery object properties parameter-passing