-
Dec 21st, 2011, 03:45 PM
#1
Thread Starter
Hyperactive Member
[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 03:31 AM.
-
Dec 21st, 2011, 07:48 PM
#2
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?
-
Dec 22nd, 2011, 02:08 AM
#3
Thread Starter
Hyperactive Member
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.)
-
Dec 22nd, 2011, 02:21 AM
#4
Thread Starter
Hyperactive Member
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"
-
Dec 22nd, 2011, 03:30 AM
#5
Thread Starter
Hyperactive Member
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)
-
Jul 25th, 2013, 06:13 PM
#6
New Member
Re: [ABANDON] Calling jQuery Plugin Add Method
Firstly - let me just say what a painfully difficult forum to register for.
I'm only posting here because I lost hours trying to solve this problem.. And this site ranks in the top search results for "wl_Multiselect('add'"
If you are using wl_Multiselect and want to have id's matched to the items in the select box - they can not be added as all the documentation indicates. The below works fine:
Where data is an array containing id, name and selected. The selectbox in question is id="selDepartments"
Code:
$.each(data, function (index, record) {
var id = record.id;
var name = record.name;
var newOption = {};
newOption[id] = name;
$('#selDepartments').wl_Multiselect('add', newOption);
if(record.selected != 0) {$('#selDepartments').wl_Multiselect('select', id)};
});
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|