hi,
i do stuff the clumsy way and overlook something completely obvious.
my issue is that i try to map some very ugly API responses into a much
saner data structure in a view. i did that in the first run simply
this way:
function(doc) {
emit(doc.domain,
{domain: doc.domain,
auth: doc.PROPERTY.AUTH[0],
created: doc.PROPERTY.CREATEDDATE[0],
expire: doc.PROPERTY.EXPIRATIONDATE[0],
ns: doc.PROPERTY.NAMESERVER,
status: doc.PROPERTY.STATUS,
renew: doc.PROPERTY.RENEWALMODE[0],
owner: {
firstname: doc.PROPERTY.OWNERCONTACT.PROPERTY.FIRSTNAME[0],
lastname: doc.PROPERTY.OWNERCONTACT.PROPERTY.LASTNAME[0],
company: doc.PROPERTY.OWNERCONTACT.PROPERTY.ORGANIZATION[0],
street: doc.PROPERTY.OWNERCONTACT.PROPERTY.STREET[0],
.....
then reality caught me and i noticed that some of the values i try to
assign are actually not always there so i came up with this:
.......
firstname: doc.PROPERTY.OWNERCONTACT.PROPERTY.FIRSTNAME[0] || '',
lastname: doc.PROPERTY.OWNERCONTACT.PROPERTY.LASTNAME[0] ||
doc.PROPERTY.OWNERCONTACT.PROPERTY.NAME[0],
company: doc.PROPERTY.OWNERCONTACT.PROPERTY.ORGANIZATION[0] || '',
street: doc.PROPERTY.OWNERCONTACT.PROPERTY.STREET[0] || '',
.......
but obviously i get still errors as for example the
doc.PROPERTY.OWNERCONTACT.PROPERTY.FIRSTNAME key is not defined at all
and so the array i try to get the first element of is undefined and
throws an error.
any sane way i can do it nicely in the emit function or do i have to
write a proper parser :-)
cheers
lenz
--
iWantMyName.com
painless domain registration (finally)