I m newbie in jquery space and hope to learn much through Stackoverflow.
I have a Sharepoint 2010 list data item which has Choice data type allowing a user to checkbox more than one value. I m using SPService to get the list items. Below is the code:
$().SPServices({
webURL: 'http://abc.def.com/Products',
operation: 'GetListItems',
listName: listName,
async: false,
CAMLQuery: query,
CAMLViewFields: fields,
CAMLRowLimit: 11,
completefunc:
function (xData, Status)
{ $(xData.responseXML).find("[nodeName=z:row]").each(function ()
{
$("#ProdList").val("-1");//Pre-filled with selected val.
var myProd= $(this).attr("ows_Prod"); //displays in this format ;#myProd1;#myProd2;#
//Here 1. i want to store myProd as an array.
2. eliminate ;#
3. store final array elements as myProd1, myProd2
4. Display myProd1
myProd2
in the dropdown list.
//
$("#ProdList").append('<option>' + myProd+ '</option>');
});
}
});
});
<body>
<select class="Dropdowns" id="ProdList">
<option value="-1">My ProdLists</option>
</select>
</body>
Any pointers? Thanks.
It’s a bit hard to figure out what the specifics are of your question. I’m guessing that the comments in your code are describing the question. Next time, I’d suggest you be a lot more specific with the details of your question in your text, not in the code. But, given that, here’s my guess at what you’re trying to do.
You have a string that looks like this:
And, you’d like to get
myProd1andmyProd2into an array and then from that array added to a drop-down list.You can sort the array in dictionary order with:
You can remove dups from a sorted array with this:
So, if you wanted to both sort and remove dups, you could use this code: