Friends
I have some feature results coming back from a queryTask to populate a grid.
This return gives me the correct data
var data = arrayUtils.map(results.features, function (feature) {
return { "id": feature.attributes["OBJECTID"],
"NAME": feature.attributes["PARCELID"]
{
});
but I would like just the first two fields without explicitly naming them.
Something like this?
return { "id": feature.attributes[outFields[0]],
"NAME": feature.attributes[outFields[1]]
}
Just can't get it.
Any syntax suggestions?
Keith
Solved! Go to Solution.
Thanks!
Odd it didn't work, but you could hack together that outFields array and try it the way you have in your example.
Something like:
var outFields = Object.keys(feature.attributes); //var outFields = Object.keys(features[0].attributes); //> I would do this when you first get results return { "id": feature.attributes[outFields[0]], "NAME": feature.attributes[outFields[1]] };
If you are using an older version of IE, you could use dojox/lang/functional/object to get the keys.
It's a little odd to do it that way but I think that would definitely work. maybe
A QueryTask returns a couple of pieces of info you could use. It returns a fieldAliases array and a fields array.
The fields array isn't listed in the docs, but it's on the REST spec.
Anyway, you could do something like
return { "id": feature.attributes[featureSet.fields[0].name], "NAME": feature.attributes[featureSet.fields[1].name] };
It's a little odd, but that could work.
Thanks!
Odd it didn't work, but you could hack together that outFields array and try it the way you have in your example.
Something like:
var outFields = Object.keys(feature.attributes); //var outFields = Object.keys(features[0].attributes); //> I would do this when you first get results return { "id": feature.attributes[outFields[0]], "NAME": feature.attributes[outFields[1]] };
If you are using an older version of IE, you could use dojox/lang/functional/object to get the keys.
It's a little odd to do it that way but I think that would definitely work. maybe
It's probably not working as you won't be able to read the featureSet object which is assigned outside the scope of arrayUtil.map function. So you need to pass "this" context using lang.hitch.So add module "dojo/_base/lang" as lang and try following:
featureSet = results;
var data = arrayUtils.map(results.features, lang.hitch(this,function (feature) {
return {
"id": feature.attributes[featureSet.fields[0].name],
"NAME": feature.attributes[featureSet.fields[1].name]
{
}));
Thank you Mahtab!