Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

This just be so obvious but I it seems not. Below I stripped out some of the code for clarity

 var list = context.get_web().get_lists().getByTitle('SMenuLink')

 //usual code to open a list using CSOM

 context.load(allItems,"Include(Title,SubMenuItemId,SubMenuItemText)
  //a array to hold our JSon stringifer objects
  var subMenuItems = [];

 // loop through the list
 {
    var subMenuItem = JSON.stringify(listItem.get_fieldValues());

    // create a Json Object with sringifier
    subMenuItems.push(subMenuItem)

 } 

Now I want to reference the one of the array items and pick the field value

  var daniel = subMenuItems[0].SubMenuItemText;
  alert(daniel);

I can see that array item [0] looks perfect in firebug but I not for the first time in my life am still "undefined"!!!! Therefore, my syntax is obviously wrong.....

share|improve this question

1 Answer 1

I am not a Client API expert by any means, but does get_fieldValues() get JUST the field values?

I thought it would store an object like: {"Title":"Task 1","SubMenuItemId":"1","SubMenuItemText":"My funcky text"}

Maybe you need to seperate the field title and field value in your "var daniel = subMenuItems[0].SubMenuItemText;" line?

Just a thought,

Mark

share|improve this answer
    
Mark I think you are on the right lines and yes the object array as seen in firebug looks exactly like you have depicted. It will be something like subMenuItems.somthng[0].SubMenuItemText; –  westerdaled Feb 20 '13 at 11:55
    
Mark, Jimmy and Alex.... After a bit of time staring blankly at FF ... It dawned on my that I was just dealing an array of strings in json format and not objects. Tried every thing I could think of to instanstiate the json on object with a {} syntax..all I acheived was a headache and multiple FF crashes. Then after a bit of googling I spotted this devcurry.com/2010/12/resolve-json-is-undefined-error-in.html . Thereafter, the answer was obvious –  westerdaled Feb 21 '13 at 13:28
1  
var daniel = JSON.parse(subMenuItems[0]); daniel.subMenuItemText; // at last I am not undefined!!! –  westerdaled Feb 21 '13 at 13:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.