开发者

How to display specific field using jquery?

开发者 https://www.devze.com 2023-02-04 06:47 出处:网络
I have aPersonVO object having fields firstname, lastname, id. I am preparing an Arraylist of PersonVO objects in backend with the help of Json API, and I want to display it in frontend with the hel

I have a PersonVO object having fields firstname, lastname, id.

I am preparing an Arraylist of PersonVO objects in backend with the help of Json API, and I want to display it in frontend with the help of jQuery.

How to display only specific fields 开发者_高级运维without hard-coding the fields in frontend like this.firstname or this.id or this.lastname, possibly hiding the id field?


You can use $.each to traverse through all object properties.

Example: http://jsfiddle.net/u78Ce/

Edit: I think you meant to save the keys somewhere in your program, and later access that key of an Object. In javascript, for objects, a.var is the same as a['var']. So you could do something like

var first_name_column = 'firstName', last_name_column = 'secondName';

Then later in your code, access them like

var person = { firstName: "John", lastName: "Doe" }; 
var fn = person[first_name_column], ln = person[last_name_column];
0

精彩评论

暂无评论...
验证码 换一张
取 消