Results 1 to 5 of 5

Thread: [ABANDON] Calling jQuery Plugin Add Method

  1. #1
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 10
    Location
    Cape Town
    Posts
    440

    Resolved [ABANDON] Calling jQuery Plugin Add Method

    I'm having a problem calling a jQuery plugin to add elements.

    Please check the "add" method of this plugin: http://revaxarts-themes.com/whitelab...ml#multiselect

    In my code I have a jQuery Ajax call which will bring back a json result (collection of "employee" objects)
    The data comes back fine, and I can add employees to my list as follows:
    Code:
    // Load all employees in selected team
    $("select#TeamId").change(function () {
        allAgentsList.empty();
        var teamId = $("select#TeamId > option:selected").attr("value");
        $.ajax({
            type: "POST",
            url: urlGetTeamEmployees,
            data: { teamId: teamId },
            success: function (returndata) {
                if (returndata.data.length > 0) {
                    $.each(returndata.data, function (index, itemData) {
                        var id = itemData.Id;
                        var name = itemData.FirstName + ' ' + itemData.LastName;
                        $('#SelectedAgents').wl_Multiselect('add', name );
                    });
                }
            }
        });
    });
    However, I want to add the items with it's Id and Name (above just use name) and I used many variations of the add method (as per that link) without luck, such as:
    $('#SelectedAgents').wl_Multiselect('add', { id : name } ); etc (the documentation strangely are quite how to add a single item at a time, passing both value and text.

    Any idea?
    Last edited by Krokonoster; Dec 22nd, 2011 at 02:31 AM.


  2. #2
    Frenzied Member
    Join Date
    Apr 09
    Location
    CA, USA
    Posts
    1,500

    Re: Calling jQuery Plugin Add Method

    By the documentation, $('#SelectedAgents').wl_Multiselect('add', { id : name }) looks like the right way to do it. What happens when you try that? Nothing? Errors?

  3. #3
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 10
    Location
    Cape Town
    Posts
    440

    Re: Calling jQuery Plugin Add Method

    Little hard to describe, but let me try this way:
    The output (correct) for $('#SelectedAgents').wl_Multiselect('add', name); is:
    Code:
    <li data-value="krokonoster">
      <a>krokonoster</a>
      <a class="remove"></a>
    </li>
    Needless to say, the "data-value" should be the id I have, but doing the way you suggest gives you:
    Code:
    <li data-value="id">
      <a>krokonoster</a>
      <a class="remove"></a>
    </li>
    (in the last case, the id was definitely set.)


  4. #4
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 10
    Location
    Cape Town
    Posts
    440

    Re: Calling jQuery Plugin Add Method

    Weird..
    $('#SelectedAgents').wl_Multiselect('add', { 123: name })
    Works fine (each item's data-value is 123.
    But replace 123 with id (which always is a number)....the data-value is "id"


  5. #5
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 10
    Location
    Cape Town
    Posts
    440

    Re: Calling jQuery Plugin Add Method

    Abandon this one. Tried to be cute, but rather going to change to a normal list of items with checkboxes. (even i get it right, posting the MVC way is impossible)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •