4
\$\begingroup\$

I have some code that reads from an XML file and updates if needed. I want to move some of the stuff around. Here is the code overall:

 priv.refAddUpdate = function(addressDoc, addressLine, value)
{
  if(!S(value).isEmpty())
  {
     var found = $(addressDoc).find('addressLines').find(addressLine);

     if(found.length > 0)
     {
        found.text(value);
     }
     else
     {
        $(addressDoc).find('addressLines').append('<addressLine>' + value + '</addressLine>');
     }
  }
  else
  {
     $(addressDoc).find(addressLine).remove();
  }
   };
   priv.updateAddress = function(addressDoc, address)
   {
  if(addressDoc)
  {
     priv.addUpdate(addressDoc, 'firstName', address.firstName);
     priv.addUpdate(addressDoc, 'middleName', address.middleName);
     priv.addUpdate(addressDoc, 'lastName', address.lastName);
     priv.addUpdate(addressDoc, 'companyName', address.companyName);
     priv.refAddUpdate(addressDoc, ':nth-child(1)', address.address);
     priv.refAddUpdate(addressDoc, ':nth-child(2)', address.ref1);
     priv.refAddUpdate(addressDoc, ':nth-child(3)', address.ref2);
     priv.addUpdate(addressDoc, 'city', address.city);
     priv.addUpdate(addressDoc, 'state', address.state);
     priv.addUpdate(addressDoc, 'zip', address.zip);
     $(addressDoc).find('countryCode').text(address.country);
     $(addressDoc).find('shipMethod').text(address.shipMethod);
     priv.addUpdate(addressDoc, 'phoneOne', address.phoneOne);
     priv.addUpdate(addressDoc, 'phoneTwo', address.phoneTwo);
     priv.addUpdate(addressDoc, 'email', address.email);
     }
  };

the big thing is I want to move the :nth-child(1)||:nth-child(2)||:nth-child(3) up into this so that way I can just call perhaps a 1 2 or 3 based on the child instead of how it is now.

priv.refAddUpdate = function(addressDoc, addressLine, value)
    {
  if(!S(value).isEmpty())
  {
     var found = $(addressDoc).find('addressLines').find(addressLine);

     if(found.length > 0)
     {
        found.text(value);
     }
     else
     {
        $(addressDoc).find('addressLines').append('<addressLine>' + value + '</addressLine>');
     }
  }
  else
  {
     $(addressDoc).find(addressLine).remove();
  }
  };

Perhaps it would look like this:

 priv.refAddUpdate(addressDoc, '(1)', address.address);

Or something close to that. Any advice would be awesome!

\$\endgroup\$
  • \$\begingroup\$ Anything guys?, \$\endgroup\$ – Norcal Jun 13 '16 at 5:06
  • 1
    \$\begingroup\$ where does priv come from? please [edit[ your post to explain this \$\endgroup\$ – Sᴀᴍ Onᴇᴌᴀ Oct 12 '19 at 5:29

Browse other questions tagged or ask your own question.