3

I have:

IN THE HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Buscador</title>
    <script src="lib/jquery-1.4.4.js" type="text/javascript"></script>
    <script src="buscador.js" type="text/javascript"></script>  
    <script src="lib/jquery.autolink.js" type="text/javascript"></script>   
</head>
<body       
    <h1>Buscador</h1>
        Esta es la prueba de poner tooltip a una no mas Prueba para ver
        El elemento solo tiene que tener el atributo title="mensaje del tooltip" y 
</body>
</html>

And in the javascript:

function getList(){
    //_listDiccionario = Array(new Array("elemento","Este es el mensaje"), new Array("mensaje","cosas rarascosas ")); //Para probar

    /* Retrieves the current ClientContext object */
     //var context = SP.ClientContext.get_current();

    var webUrl = "http://c-jfmunoz:5000";  
    var context = new ClientContext(webUrl); 

    var web = context.get_web();

    // Get references to the lists we will use
    var listObject = web.get_lists().getByTitle(_listName);

    // Get the list items for the contacts list 
    _listDiccionario = listObject.getItems();

    // context.load tells the object model to load the objects scalar 
    // properties. Otherwise they will not be accessible 
    context.load(_listDiccionario);
    context.load(listObject);
    context.executeQueryAsync(onListsLoaded);
}

/* 
    Event handler called loading the contacts and companies lists
    This method dynamically renders an HTML table to display the list data 
*/

function onListsLoaded() {
    addToolTipToList("body","0000FF",_listDiccionario);
    return false;
}

And when I run it it says "ExecuteOrDelayUntilScriptLoaded was not defined"

I think that nothing will work. Is there anything that I must add to the JavaScript file to make it work?

2 Answers 2

1

Have you included any of the SharePoint javascript code in your page? ie: script refs to sp.js?

Also, where is your HTML page running from? I'm not sure if it works outside the context of a SharePoint site.

If you need a hand getting started with the JavaScript Client Object Model, have a read through this tutorial:

http://www.codeproject.com/Articles/60348/SharePoint-2010-Client-Object-Model-for-JavaScript.aspx

0

Now it's working :)

The problem now is that I have a list called 'Lista Diccionario' and I want to get all the items there.

"There's the code" but it doesn't work.

look:

var _listName = "Lista Diccionario";
var _listDiccionario;

$(document).ready(function() 
{
    //_spBodyOnLoadFunctionNames.push("Initialize()");
    ExecuteOrDelayUntilScriptLoaded(initialize, "sp.js");  
    //getList();
    //addToolTipToList("body","0000FF",_listDiccionario);
});

function initialize(){
    getList();
}

function addToolTipToList(where, color, list){
    for( i=0 ; i < list.length ; i++){
        addTooltipToText("body", "0000FF", list[i][0], list[i][1]);
    }
}

function addTooltipToText(where, color, text, tooltipMessage) {
   $(where).replaceEachOne(text, '<label style="color:#'+ color + ';" title="' + tooltipMessage + '">$1</label>');
}

//Ejemplo en http://sharepointbloggin.com/2010/02/10/walkthrough-4-accessing-list-data-using-the-javascript-client-om/
    function getList(){
        //_listDiccionario = Array(new Array("elemento","Este es el mensaje"), new Array("mensaje","cosas rarascosas ")); //Para probar

        var ctx = new SP.ClientContext.get_current();
        this.web = ctx.get_web();
        ctx.load(this.web);

        /*var webUrl = "http://c-jfmunoz:5000";  
        var context = new ClientContext(webUrl); */

        // Get references to the lists we will use
        var listObject = web.get_lists().getByTitle(_listName);

        ctx.load(listObject);

        // Get the list items for the list 
        _listDiccionario = listObject.getItems();

        // context.load tells the object model to load the objects scalar 
            // properties. Otherwise they will not be accessible 
            ctx.load(_listDiccionario);

            ctx.executeQueryAsync(Function.createDelegate(this, this.onListsLoaded),
                                    Function.createDelegate(this, this.onListsFailed));
        }

    /* 
        Event handler called loading the contacts and companies lists
        This method dynamically renders an HTML table to display the list data 
    */
    function onListsLoaded(sender, arg) {
        addToolTipToList("body","0000FF",_listDiccionario);
        return false;
    }

    function onListsFailed(sender, args) {
        alert('failed to update title. Error:'+args.get_message());
        return false;
    }

UPDATE:

I change the name of the list from "Lista Diccionario" to "Diccionario" and now it works!!!

1
  • It goes to the onListsFailed method, Where's the error? Jan 17, 2011 at 20:58

Your Answer

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

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