Instead of building up a comma-separated string, and then splitting that up into an array, instead perhaps consider building up a List<string> which you can check for dupes before actually adding. Here's a rough idea (untested) on what I mean by this:
List<string> hotelNodes = new List<string>();
foreach(var season in Model.Children.Where("Visible"))
{
if (!hotelNodes.Contains(season.seasonHotels))
{
hotelNodes.Add(season.seasonHotels);
}
}
string[] accommodations = hotelNodes.ToArray<string>();
This is assuming the type of season.seasonHotels is actually a string, instead of a DynamicXml or something, but if so, just add the appropriate casting where needed. Despite this, however, there are two things I'm curious about:
First, my experience with the uComponents Multi-Node Tree Picker has been that it doesn't allow me to select duplicates, even when I try.
Second, I'm thinking you could combine your two separate code blocks/loops into a single comprehensive loop? That is, don't bother with building up an array of nodes and then later iterate through them --- just loop once the first time and do your magic right there?
I have played around with the List<>. I wasn't able to make your suggestion work just like that. I have chaged the multi-node tree picker to save the data as XML to see if that helped enything. Right now I'm testing this:
List<string> hotelIds = new List<string>(); foreach (var s in Model.Children) { if(s.seasonHotels != null) { foreach (var h in s.seasonHotels.InnerText.ToString()) { hotelIds.Add(h.ToString()); } } } <ul> @foreach(var hid in hotelIds) { <li>@hid</li> } </ul>
Select distinkt nodeId's from multi-node tree picker
How do I select only unique nodeId's from a multi-node picker?
So far, I got this:
And then...
It is Umbraco 4.7.2.
Instead of building up a comma-separated string, and then splitting that up into an array, instead perhaps consider building up a List<string> which you can check for dupes before actually adding. Here's a rough idea (untested) on what I mean by this:
This is assuming the type of season.seasonHotels is actually a string, instead of a DynamicXml or something, but if so, just add the appropriate casting where needed. Despite this, however, there are two things I'm curious about:
First, my experience with the uComponents Multi-Node Tree Picker has been that it doesn't allow me to select duplicates, even when I try.
Second, I'm thinking you could combine your two separate code blocks/loops into a single comprehensive loop? That is, don't bother with building up an array of nodes and then later iterate through them --- just loop once the first time and do your magic right there?
Best of luck to you!
Hi again
I have played around with the List<>. I wasn't able to make your suggestion work just like that. I have chaged the multi-node tree picker to save the data as XML to see if that helped enything. Right now I'm testing this:
It gives me this:
1
1
2
2
1
1
2
2
1
1
6
2
Not exatly what I want... Any ideas?
If I do it like this, it works. I have combined my original code with some of Funka's suggestion.
is working on a reply...