I want to parameterize my javascript routine so I can pass the field name that I want to use to populate from the list I've got back from my JSON interface. i.e, I want to convert my getRoutes() function (below) to getTable(), and pass the table name "Routes" and the field I want it to use, "routeId". "Routes" obviously isnt an issue as it's just passed to my JSON api, but how do I get "routeId" into the code ?. java has stuff like getDeclaredField, what's the javascript for that ?. I thought it was getValue, as in
items.push("<option>" + val.getValue(keyName) + "</option>");
but that didnt work.
Here's my original working code that I want to generalise,
function getRoutes(){
$.getJSON( "/GeeREST/Entity?entity=Routes",
function( data ) {
var items = [];
$.each( data, function( key, val ) {
items.push("<option>" + val.routeId + "</option>");
});
...
And here's what I am trying to do
function getTable(tableName,keyName){
$.getJSON( "/GeeREST/Entity?entity="+tableName,
function( data ) {
var items = [];
$.each( data, function( key, val ) {
items.push("<option>" + val.getValue(keyName) + "</option>");
});
...
data[keyName]what you are looking for?var fieldname = "routeid"; var value = val[fieldname]. Is that what you are trying to do?