Selecting Specific Lists

Asked

Viewed 114 times

1

I have the following code to return the libraries of my Sharepoint project:

function retornarLista() {
    collList = website.get_lists();

    context.load(collList);//, 'Include(TemplateType==109)'
    context.executeQueryAsync(onQuerySucceeded, onQueryFailed);
}

function onQuerySucceeded() {
    var listInfo = '';
    var listEnumerator = collList.getEnumerator();

    while (listEnumerator.moveNext()) {
        var oList = listEnumerator.get_current();
        listInfo += 'Title: ' + oList.get_title() +
            ' ID: ' + oList.get_id().toString() + '\n';
        $("#biblioteca").append("<option value='" + oList.get_id().toString() + "'>" + oList.get_title() + "</option>");
    }
}

function onQueryFailed() {
    alert("Failed");
}

I would like to return only the Image Libraries to transfer to a dropdown of select, but I haven’t been able to, someone can help ?

  • You are using Sharepoint 2010 or 2013?

  • I’m using the 2013

  • You can check the templateID of the list to see if it is a library. I don’t know about image-only libraries - if it’s a content type (content type), you can check if each returned list has this type, and filter why.

  • So, in the user interface that I’m doing, he needs to choose whether to use an existing list or create a new one, and to make use of <Code - > var listCreationInfo = new SP.Listcreationinformation(); listCreationInfo.set_title(listName); listCreationInfo.set_templateType(SP.ListTemplateType.pictureLibrary); <End Code - >

1 answer

1


You are working with the Sharepoint JCOM library. The list object definition for this library can be seen at this link:

http://msdn.microsoft.com/en-us/library/office/jj245826(v=office.15). aspx

Note that there is property called baseTemplate.

When you create a list, you are indicating its base template (by your comment, SP.ListTemplateType.pictureLibrary).

Your code is almost complete, just missing now you go through all the lists you got in the query and check if the baseTemplate of them corresponds to the pictureLibrary template you use to create them. When matching is because the list is an image library :)

editing to include code: just adjust your code more or less like this:

/* .. snip .. */
while (listEnumerator.moveNext()) {
    var oList = listEnumerator.get_current();
    if (oList.get_baseTemplate() == SP.ListTemplateType.pictureLibrary) { // Eis o pulo do gato.
        listInfo += oList.get_title() + '\n';
    }
    /* .. snip .. */
}

By the way that SP.ListTemplateType.pictureLibrary is a constant value, 109. Living and learning, I didn’t know this template...

  • Thank you Renan, I didn’t know the baseTemplate property, but would you tell me how I would apply it in my code ? D: Thank you very much !!!

  • @Pedroelias I edited the answer, take a look.

  • also edited my code, could not apply running, did not return anything because of select I had to do ... changes something ?

  • Maybe you need to call the function load from the context passing the collection of lists, and then running QueryAsync again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.