w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Removing class of nested list elements based off click on outer list element?
You need this on click of A- $(this).closest('ul').find('li.active').removeClass('active'); $(this).closest('li').addClass('active') Demo -------> http://jsfiddle.net/NrGGz/

Categories : Javascript

Split List into Sublist using Linq based on content of list
Maybe? var list = new List<int>() { 1, 2, 0, 3, 4, 5, 0, 6 }; var subLists = list.Split(0).ToList(); IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> list, T divider) { var temp = new List<T>(); foreach (var item in list) { if (!item.Equals(divider)) { temp.Add(item); } else { yield return temp; temp = new List<T>(); } } if (temp.Count > 0) yield return temp; }

Categories : C#

How do I append list items
  • from an Unordered list
  • var lists = { numbers: [], AH: [], IP: [], QZ: [] }; $('.brand').each(function () { var letter = $.text(this).substr(0, 1); if ( /d/.test(letter) ) { lists.numbers.push(this); } else if ( /[a-h]/i.test(letter) ) { lists.AH.push(this); } else if ( /[i-p]/i.test(letter) ) { lists.IP.push(this); } else if ( /[q-z]/i.test(letter) ) { lists.QZ.push(this); } }); $('.brand-directory-list-num').append( lists.numbers ); $('.brand-directory-list-ah').append( lists.AH ); $('.brand-directory-list-ip').append( lists.IP ); $('.brand-directory-list-qz').append( lists.QZ ); Here's the fiddle: http://jsfiddle.net/q697n/ If you want to make the code a little DRYer, you can store the regular expressions in a map objec

    Categories : Javascript

    Semantic elements for footnote list and content
    There isn't any dedicated mechanism yet, but footnotes either with linked, or simple footer notes with list elements as well as side notes can be merged into a common suggested alternative markups. You might have seen this already - "HTML5 Common Idioms without dedicated elements" Sure it's more viable to wrap each footnotes within a <section> element if more than one occurs within a single <article>. If that's not the case you can wrap 'em within <footer> or <aside>. Then content elements follows as usual. Like <p> for descriptive segments. Here is another example of "Footnotes with micorformats"

    Categories : HTML

    Does any-one have a list of the permissible content elements for each SVG element?
    { "altGlyphDef" => ["glyphRef", "altGlyphItem"], "animate" => ["desc", "metadata", "title"], "animateColor" => ["desc", "metadata", "title"], "animateTransform" => ["desc", "metadata", "title"], "circle" => [ "animate", "animateColor", "animateMotion", "animateTransform", "set", "desc", "metadata", "title", ], "clipPath" => [ "desc", "metadata", "title",

    Categories : Perl

    Why does adding a list to another list, using add range, remove the elements from the first list?
    It's because of the IEnumerable. When you set groupsToAdd to the result of groups1.Where(g => false == groups2.Contains(g)) there is deferred execution, which means that the query is not run until AddRange() and then again at Dump(). Because the list, groups2, now contains the elements they no longer are a result of the original query.

    Categories : C#

    create a list from another list and remove elements from copied list
    Yes your understanding is correct. List newList = new ArrayList(collection); will do a shallow copy. You can modify the newList without affecting the original collection, but they will each reference the same elements so if you modify an element in one list, the other list's element will also get the change. This is called a Shallow Copy. Here's a visual representation of what I've described: The things at the bottom are the objects in your array.

    Categories : Java

    Get content of list of span elements with HTMLUnit and XPath
    text() will only extract the text from that element, and that example you've given has no text component, only a child element. Try this instead: List<?> topics = (List)page.getByXPath("//span[@class='topic']");

    Categories : Java

    find elements include a text in List
    to check list for values primes.Contains(2) to know indexes for each element can do var foo = primes.Select((x, i) => new { x, i }).ToLookup(x => x.x, x => x.i); this will group elements and their respective indexes

    Categories : C#

    Disabling form elements based on condition of dropdown list
    You need to separate the on change action for both dropdowns e. g $("select[name='card']").change(function(){ ... }) $("select[name='pensioncard']").change(function(){ ... }) check the jsfiddle $("select[name='card']").change(function(){ var disableIt=$(this).val()=='N' ? true : false; $("#cardtype").attr("disabled",disableIt); $("#insurancecardnumber").attr("disabled",disableIt); $("#cardexpiry").attr("disabled",disableIt); }); $("select[name='pensioncard']").change(function(){ var disableIt=$(this).val()=='N' ? true : false; $("#pensioncardnumber").attr("disabled",disableIt); $("#pensioncardexpiry").attr("disabled",disableIt); }); On server type of bug you have is if($("#pensioncard").val("N")) will always s

    Categories : Javascript

    Align
  • elements with list-type:outside style to the content border consistently
  • I suggest using something like this: ul { list-style-position: inside; margin:0px; padding:0px; } http://jsfiddle.net/Um5L9/4/

    Categories : HTML

    iterate through ListView and delete list items based on their content
    I'm not sure you understand how ListView works. A ListView is the visual representation of the data in your adapter, so you should never try to edit, add or delete views of a ListView directly, but instead edit the data and then call notifyDataSetChanged() on your adapter. The ListView will then check for changes in your adapter's data and refresh the views accordingly. For your specific problem, it means that you should work directly with mPendingItemList, find the items that have a specific content, remove them and then call notifyDataSetChanged().

    Categories : Android

    How to find elements that are common to all lists in a nested list?
    You can use reduce and set.intersection: >>> reduce(set.intersection, map(set, nested_list)) set([2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0]) Use itertools.imap for memory efficient solution. Timing Comparisons: >>> lis = [[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0], [2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0], [1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0], [2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0]] >>> %timeit set.intersection(*map(set, lis)) 100000 loops, best of 3: 12.5 us per loop >>> %timeit set.intersection(*(set(e) for e in lis)) 10000 loops, best of 3: 14.4 us per loop >>> %timeit reduce(

    Categories : Python

    Iterating through a list of elements and removing the cursor style on them based on inner text
    The line: var planLinks = $('.status-progress, .plan-name a'); ...will select all such anchor elements, not just the ones related to the current iteration of the .each() loop. One way to get just the related ones is: var planLinks = $(this).closest("div").find("a"); That is, use DOM traversal methods to find the containing div and then select the anchors within it. Or you could go based on siblings, etc., but that is more fragile since a change to the html structure is then more likely to require a change to the JS. But you don't really need the .each() loop if you do something like this instead: $("a.status-progress:contains('in progress')") // find the 'in progress' anchors .closest("div") // get their containing divs .find("a")

    Categories : Javascript

    Abnormal behaviour of java.util.List based on number of elements in it
    It seems when you remove the specified element from the list,the list does not know its size have been changed. Try this: Iterator.remove() Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.

    Categories : Java

    Predicate for NSFetchRequest Core Data based on content in other entity list
    CoreData is an object graph representation of your data, in most cases it is backed up by an SQLite database. I assume that you need to sync your objects with a server side database and so you must define your own user_id property. However, it might make sense for you to make a relationship between a User entity and a ContactStatus entity (this depend on your implementation and application needs that you have not listed). In any case, under your current implementation (assuming your query target entity is ContactStatus). Your predicate should look something like: [NSPredicate predicateWithFormat:@"(first_user_id = %@ OR second_user_id) AND status = %@",@(u_id),@(u_id),@"CONF"];

    Categories : IOS

    How to get the list elements using list inside another list in java
    You can try this ,Let say you have variables like double dtime; Timestamp tp; And listofresults is coming from query results. listofresults = results.getResultList(); If list is coming from query then put it in the loop this way in the condition of for loop for(int i=0;i< listofresults.size() ;i=i+2) { dtime=(double) listofresults.get(i); //cast because the value is of object type tp=(TimeStamp) listofresults.get(i+1); //cast because the value is of object type //do something with these variables }

    Categories : Java

    Using a list as "list of indexes" to address elements of another list
    You could use reduce(operator.getitem, index, mylist) Here is a complete example: import operator mylist = [[1,2,3],[4,5,6],[7,8,9]] index = [1,2] val = reduce(operator.getitem, index, mylist) print(val) For NumPy arrays, there is a simpler method: import numpy as np ... myarr = np.array(mylist) val = myarr[tuple(index)] print(val)

    Categories : Python

    How to "unzip" then slice and find max for elements in a list of lists in Python
    max(int(subl[0].rsplit('-',1)[1]) for subl in L) This will return 3. If you want to print '003', then you can do this: print "%03d" %max(int(subl[0].rsplit('-',1)[1]) for subl in L) Explanation: As you seem to already know, max takes a list of numbers and returns the largest one. This is almost correct: max takes any interable and returns the largest element. A generator is an iterable and takes O(1) space as opposed to a list, which takes O(n) space. You can also use a list comprehension to create a generator (called a generator comprehension), which is what I have done. (int(subl[0].rsplit('-',1)[1]) for subl in L) is the same as: def myGen(): for subl in L: elem = subl[0] myNum = elem.rsplit('-', 1) myNum = int(myNum) yield myNum max(myGen)

    Categories : Python

    Find latest entries in a list based on a field
    You can use takeWhile(): ​assert [1,2] == [1,2,3,4,5].takeWhile { it < 3 }​ EDIT(Audacity of @dmahapatro to edit answer) Small test case for available statuses other than Accepted and Ready: def list = ['A', 'A', 'B', 'A', 'R', 'A'] assert list.takeWhile{ it == 'A'} == ['A', 'A'] assert list.takeWhile{ it != 'R'} == ['A', 'A', 'B', 'A']

    Categories : Grails

    Find duplicate items in list based on particular member value
    How can I find duplicate items in list based on particular value and group the duplicated items together? Sounds like GroupBy to me. You've already done that grouping in the code in the question - you just need to use the results. The result of GroupBy is a sequence of groups where each group is a key and a sequence of values sharing that key. For example: foreach (var group in Customers.GroupBy(x => x.emailaddress)) { Console.WriteLine("Customers with email address {0}", group.Key); foreach (var customer in group) { Console.WriteLine(" {0}", customer.Name); // Or whatever } }

    Categories : C#

    How do find pairs, which have equal content? in Collection>? use some library
    List<String> result = new ArrayList<String>(); result =((ArrayList<List<String>>) collection).get(0); for (int i=1;i< collection.size(); i++) { result.retainAll(((ArrayList<List<String>>) collection).get(i)); } result will have [object1, object2]

    Categories : Java

    How to show inner content in list item outside of that list item without being covered up by descending list items
    You must set the z-index of the clicked 'li' higher and in return the former clicked 'li' back. Here is the example: fiddle And here the script: var oldli; $('li').click( function(){ $(oldli).toggleClass('displayNone displayBlock'); $(oldli).css("z-index","1"); $(this).toggleClass('displayBlock displayNone'); $(this).css("z-index","5"); oldli=$(this); } );

    Categories : Javascript

    How to make a jQuery UI droppable list where elements added to the list are also drop targets
    I think what you really want is a sortable for the users list and then all the draggable for the "eligible items" jQuery(function($) { $('#list2 li').draggable({ cursor: 'move', helper: 'clone', connectToSortable: "#list1", }); $('#list1').sortable({ revert: true, }); }); http://jsfiddle.net/petersendidit/gKtXa/5/

    Categories : Javascript

    R: Test condition on column of dataframe elements within list; return smaller list
    You can use this: myList <- myList[sapply(myList, function(d) max(d$values) != 0)] instead of the for() loop. This will let pass dataframes with zero rows, with a warning. To ensure empty dataframes are removed, use this: myList <- myList[sapply(myList, function(d) if(nrow(d)==0) FALSE else max(d$values)!=0)]

    Categories : R

    Iterating over list of list elements and returning error message if integer has certain value
    Use the any() function with a generator expression testing each nested list: if any(bread[2] > 80 for bread in breadsticks): print("You have entered too many breadcrumbs") This will only test as many nested lists as needed to find any for which the test is True. Note that it is simpler to just loop directly over breadsticks in loops: for bread in breadsticks: print(bread[2])

    Categories : Python

    Turning a chain of foreach's for inserting elements from a list into another list into linq
    What you're logically doing here is a Join operation. Your current code is actually finding all possible pairs of cities and states and then filering only the pairs that match. You could represent that in LINQ, but you wouldn't want to. There are more efficient ways of performing a Join that only generate the exact pairs that you need to begin with. The LINQ Join operator leverages this. Your code boils down to two different Join calls, and then an iteration over each result that performs the mutation of the objects based on the query. var stateCityPairs = from state in finalList join city in cityList on state.IdState equals city.IdState select new { state, city }; foreach (var pair in stateCityPairs) pair.s

    Categories : C#

    Python merge with elements list(value, id) to element: list(value, value2, id)
    You should use a dictionary here: >>> from collections import defaultdict >>> from itertools import chain >>> lis1 = [(u'0', 1), (u'3000', 2), (u'10000', 3), (u'20000', 4)] >>> lis2 = [(u'2999', 1), (u'9999', 2), (u'19999', 3), (u'999999999', 4)] >>> dic = defaultdict(list) >>> for v, k in chain(lis1,lis2): dic[k].append(v) ... >>> dic.default_factory = None # now missing IDs will raise KeyError Now access items related to any id: >>> dic[1] [u'0', u'2999'] >>> dic[2] [u'3000', u'9999']

    Categories : Python

    Keeping common elements from two list in tcl and place them in a result list
    See this question and the documentation here. This worked for Tcl 8.0 and still works on 8.5 (and I'm pretty sure 8.6 as well). % package require Tcl % package require struct::set % set ListA [list 3 4 9 1 2 10 6 ] % set ListeB [list 34 43 9 12 2 10 61 88 23 48] % ::struct::set intersect $ListA $ListeB 9 2 10

    Categories : List

    Slide a list element with jQuery without effecting other list elements
    You need to change the positioning of .block-content to position: absolute. That will fix the sliding of the other li elements. Then, to fix the positioning of the .block-content, remove width: 100%, change the right positioning to right: 0, and add top: 45px. The css for .block-content is then: .block-content { font-size: 12px; font-family: Helvetica, sans-serif; display: block; background: #333; padding: 10px; position: absolute; top: 45px; right: 0px; height: 120px; } Also, if you want the bottom of .block-content to line-up with the bottom of the li's, change the jquery to animate to 140px, not 115px. You can see the results: http://jsfiddle.net/YNBxz/1379/

    Categories : Javascript

    How to creat a new list from existing list with elements which contains the same id in Linq to object?
    list.GroupBy(x => new { x.RefId, x.RefName }) .Select(g => new TestNew() { RefId = g.Key.RefId, RefName = g.Key.RefName, ListGroup = g.Select(y => new Group() { ID = y.ID, Name = y.Name }).ToList() }).ToList();

    Categories : C#

    shared List between threads: whitin a single thread is it safe to instantiate a list referenced to the same elements?
    If fooList is indeed never modified after creation then there is no need for locks when you are reading values from it. This includes using foreach over it. If indeed fooList is never modified after creating then why not use ReadOnlyCollection<Foo> instead of List<Foo>. This is a much more declarative and enforceable method of creating a list that doesn't change. It would protect you from future accidental mutations of the list

    Categories : C#

    List multiple models in class based list and detail views in django
    You can add extra context variables by overriding the get_context_data() function in your class: class MultipleModelsListView(ListView): model = TaskA # Class names should use capitalized CamelCase def get_context_data(self, **kwargs): kwargs = super(MultipleModelListView, self).get_context_data(**kwargs) kwargs.update({ 'taskb_list': TaskB.objects.all(), # or with some filter applied 'taskc_list': TaskC.objects.all(), 'taskd_list': TaskD.objects.all(), }) return kwargs This will give you, additional to the default context supplied by a ListView, the context variables taskb_list, taskc_list and taskd_list to iterate over. You can iterate over these in your template like this: {% for task in object_list %} {#

    Categories : Django

    How to create alphabetical based list as Sencha touch grouped list but in jQuery?
    You can use data-autodividers="true" Check here http://view.jquerymobile.com/1.3.1/dist/demos/widgets/listviews/ DEMO http://jsfiddle.net/yeyene/5kfnT/6/ You can also use data-filter-reveal="true" to hide or show. For A-to-Z list navi bar I am not sure you can use with this plugin + JQM or not. Check here http://devgrow.com/slidernav-jquery-plugin/ Author page http://devgrow.com/slidernav/

    Categories : Jquery

    vba to search a list and colour code matches based on a contents list.
    I hate to encourage you, because you did not follow the site rules that say to research and attempt a solution before asking a quesiton, and share what you have already tried. That is probably why others have given your question a negative rating. However, you did enough thinking about the parameters of your problem, that I suspect you may have tried something before composing this question, and I'm granting you the benefit of the doubt. Here is a possible solution, if by "pre colour coded data" you mean the interior of the cell. Change the Constants at the top to match the column and header row of your data. If the pre colour coding of your data is something other than the interior settings I've used, you can take Marty McVry's advice of using the macro recorder to determine which set

    Categories : Excel

    How to make a list in Python distinct based on a property of the class in the list?
    Assuming the property you wish to key on is immutable, you can use a dict: d = {} for x in xs: d[x.tag] = x Now d will contain a single x per tag value; you can use d.values() or d.itervalues() to get at the xs. NB. here last matching item wins; to have the first one win, iterate in reverse.

    Categories : Python

    Create a list of integer elements from list of objects
    Use a set: sorted(set().union(first, second)) #returns a sorted list of unique items Demo: >>> first = [0,1,2,3,4,5] >>> second = [4,5,6,7,9] >>> sorted(set(first + second)) [0, 1, 2, 3, 4, 5, 6, 7, 9] If the original order matters: >>> first = [0,1,2,3,4,5] >>> seen = set(first) >>> first += [x for x in second if x not in seen and not seen.add(x)] >>> first [0, 1, 2, 3, 4, 5, 6, 7, 9] For large lists the set approach is going to be efficient as sets provide O(1) lookup, for tiny lists your approach is also okay.

    Categories : Python

    C++ : deleting multiple elements of a list while iterating the list
    In general, the way to remove elements from a list based depending on a condition is to use the std::list::remove_if member function. bool pred(const Treenode* t) { .... } currentNewLevel.remove_if(pred); The predicate can be a functor, so it can keep any state that is required to implement the removal criteria: #include <algorithm> // for std::find_if #include <list> // unary predicate functor. Returns true if an element of a reference // list satisfies "something" and the functor call argument satisfies "somethingDifferent" struct Pred { Pred(const std::list<Treenode*>& nodes) : nodes_(nodes) {} bool (const Treenode* t) const { return std::find_if(nodes_.begin(), nodes_.end(), something) != nodes_.end() && somethingDifferent(t); }

    Categories : C++

    Python: how to replace an element in a list with all elements from another list?
    If you change your data structure slightly, this is a trivial problem for the itertools module: >>> lst = [1] >>> combine = [["a", "b", "c"], ["A", "B", "C"]] >>> import itertools >>> [lst+list(item) for item in itertools.product(*combine)] [[1, 'a', 'A'], [1, 'a', 'B'], [1, 'a', 'C'], [1, 'b', 'A'], [1, 'b', 'B'], [1, 'b', 'C'], [1, 'c', 'A'], [1, 'c', 'B'], [1, 'c', 'C']]

    Categories : Python

    Filter a list based on many parameters and gather the result in another list
    If you don't have a strong reason not to, it probably makes sense to filtering on the three fields simultaneously: var filteredCards = from card in mListCards where _color == "ALL" || card.mCardColor == _color where _type == "ALL" || card.mCardType == _type where _rarity == "ALL" || card.mCardRarity == _rarity select card;

    Categories : C#



    © Copyright 2017 w3hello.com Publishing Limited. All rights reserved.