0

I defined a list where a Summary list is a coloum, in my javascript code i want to read the values of the links one by one...

sliderText = listItem.get_item('Description0');
sliderTitle = listItem.get_item('Title');
sliderLinks = listItem.get_item('SummaryLinks');

So the value of sliderLinks now is:

<div title="_schemaversion" id="_3">
  <div title="_links">
    <div title="_link">
      <span title="_title">Home</span>
      <span title="_order">1</span>
      <span title="_begincolumn">True</span>
      <span title="_linkurl">
        <a href="http://gmail.com">http://gmail.com</a>
      </span>
    </div>
  </div>
  <div title="_view">
    <span title="_columns">1</span>
    <span title="_linkstyle"></span>
    <span title="_groupstyle"></span>
  </div>
</div>

in the COM, isn't there functions to get the value of the URL and title instead of this HTML code?

2 Answers 2

1

Unfortunately the only thing CSOM gets from the server is the HTML (you can see that if you use fiddler while executing the request).

So you'll have to dig the values out of the html. If you've included jQuery you can do something like this:

    var sl = jQuery('<div></div>').html(listItem.get_item("SummaryLinks"));
    sl.find('div[title="_link"]').each(function (index, element) {
        var title = $(this).find('span[title="_title"]').text();
        var url = $(this).find('span[title="_linkurl"]').text();
        alert(title + '\n' + url);
    });
0
0

I've written a JavaScript module in an attempt to fix this shortcomming in JSOM: http://summarylinkstore.codeplex.com

With that module, you would be able to iterate the links with the following code:

var fieldValueXml = listItem.get_item('SummaryLinks');
var fieldValueObject = new oPB.SummaryLinkStore(fieldValueXml);
var summaryLinks = fieldValueObject.summaryLinks(); //returns an array
for(var i = 0, n = summaryLinks.length; i<n; i++)
{
    var summaryLink = summaryLinks[i];
    if(summaryLink.isGroupHeader()) //your example contains no group header, so if you're sure that will never happen, you limit your code to the else statement.
    {
        var groupedLinks = summaryLink.summaryLinks();
        for(var x = 0, y = groupedLinks.length; x<y; x++)
        {
            var linkInGroup = groupedLinks[x];
            alert(summaryLink.title() + " contains:" + linkInGroup.linkUrl());
        }
    }
    else
    {
        alert(summaryLink.linkUrl()); //alerts url of link, other properties are available.
    }
}

I've tried to build the module in a way that it should support any kind of operation you would like to do on the SummaryLink field and in the end be able to parse it back, so you can update the value in the list item.

My module does not make use of jQuery (or any other JavaScript library), so there should be no conflict with any JavaScript library you might want to use for other applications.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.