Accessing JSON Object
If i have a JSON Obje开发者_JAVA百科ct
var Obj = { col1 : 'data' };
the value 'col1' and 'data' are dynamically created.
Here i can access 'data' as Obj.col1. But want to read the value 'col1'.
How to do that?
How about this:
for (var name in Obj) {
alert(name)
}
Assuming your column name is available from the JavaScript:
var columnName = "col1";
alert(Obj[columnName]); // alerts "data"
If 'col1' isn't present in the object, it fails gracefully returning null
without raising an exception.
You may need to pass the the dynamic column name from serverside to clientside though. Something like:
var columnName = "<% columnName %>";
精彩评论