Search Results

Search found 16927 results on 678 pages for 'little child'.

Page 2/678 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • ASP.NET MVC - Parent-Child Table Relation - how to creat Children in MVC (example request)

    - by adudley
    Hi All. In a standard setup of Parent Child relation, lets say Project and Task. Where a Project is made up of lots of Tasks. So in a standard RDB, we have a Project (ID, Name, Deadline) Task (ID, FK_To_Project, Name, Description, isCompleted) this is all very straight forward. We have an MVC View that views Projects, so we get a nice list of all the project Names next to each deadline. Now we want to CREATE a new PROJECT. The Edit view opens, we type a name, say, 'Make a cup of Tea', with tomorrow as the deadline! Still in this view/web page, I would like a list of all the Child Tasks, in a standard list, with Edit, Delete, and a Create/Add Task button too, just below the 'parent table' details. The simplest way to describe this, is the Parents Table Create/Edit view, with the Childes List View Below it. 1) The ideal solution will also allow my Child Table (Tasks) to have Children also (for more complex scenarios) , and so on, and on, and on. 2) If I navigate away from my Created Project, I don’t want all sorts of random stuff laying around, they went away, it’s gone! 3) I’d expect all the same functionality when Editing an existing project. I’m struggling with the ‘Add New Child’, I had a model dialog (jquery) and all was well, but now when editing an existing child/task, I need to populate the Child Edit, which is a pain and will need loads of java script I think :( How can this be achieved in MVC, does anybody have any examples?

    Read the article

  • jQuery | Click child, hides parent

    - by Jamie
    Hey, I have a list of using ul and li: <span class="important">Show/Hide</span> <div id="important" class="hidden"> <ul class="sub"> <li> Value one </li> <li class="child"> <img src="../img/close.png" /> </li> </ul> </div> $(".important").click(function () { $("#important").slideToggle("fast"); }); When the child (class="child") is clicked on, it should slide up the div (id="important"), however, there are other lists that have different IDs, I want the div to slide up when the child is clicked I did this: $(".child").click(function () { $(".child < div").slideUp("fast"); }); I have no idea how to make it work, I've done other combinations, can't seem to do it.

    Read the article

  • little oh notation as the limit of n goes to infinity

    - by Tony
    Hi all, I'm just trying to understand how in little o notation this is true: f(n)/g(n) as n goes to infinity = infinity? Can someone explain that to me? I do get the idea that f(n) = o(g(n)) means that f(n) grows no faster then cg(n) for all constants c 0. I just don't get the bit in bold above.

    Read the article

  • loading "child page" inside "parent page" through javascript and functionality of "child page" throws ERROR

    - by user1304589
    i have a masterpage. Its content place holder i.e page "parent page", contains a button "Call Batch". On click "Call Batch", the "child page" is loaded in div of "parent page" using javascript without refresh! Now this "Child Page" contains a label and a button. On click of button the text of label shoud change. I want the functionality of "child page" on "parent page". I got the "child page" in "parent page" div but the functionality of "child page" is lost and i am getting error.Where to put the code of button click event which changes the text of label? Please Help.

    Read the article

  • PHP object parent/child recursion

    - by Damien
    I've got a parent-child OO relationship. Parent obejcts has many child objects and every child object knows about it's parent by reference. The parent can be a child too (basically its a tree). When i do a var_dump() on the root object it says ["parent"]=RECURSION many times and the generated description will be really long. I'm wondering if i do something wrong. If yes, i'm interested in the "best practice". Thanks for the help!

    Read the article

  • jQuery: hover (mouseleave event fired when mouse is over child)

    - by CronosS
    Hi, I want to create a zoom effect on some thumbs. Here is my javascript simplified code : parent.hover( function(){ parent.stop().animate({/* css */}, inputZoomDuration, "linear"); wrapper.stop().animate({/* css */}, inputZoomDuration, "linear"); child.stop().animate({/* css */}, inputZoomDuration, "linear"); }, function(){ alert("leave"); child.stop().animate({/* css */}, 140, "linear"); wrapper.stop().animate({/* css */}, 140, "linear"); parent.stop().animate({/* css */}, 140, "linear"); } ); and the html is like : <div parent> <div wrapper> <div child> </div> </div> </div> I increase the size of all my divs when I over the "parent". But a soon as I over (or leave, btw) one of the child, the alert appears. Without the alert, the result is a very bugy animation. Is there any way to prevent the mouseleave event to be fired when a child is overed? Best regards, thanks.

    Read the article

  • Design pattern for logging changes in parent/child objects saved to database

    - by andrew
    I’ve got a 2 database tables in parent/child relationship as one-many. I’ve got three classes representing the data in these two tables: Parent Class { Public int ID {get; set;} .. other properties } Child Class { Public int ID {get;set;} Public int ParentID {get; set;} .. other properties } TogetherClass { Public Parent Parent; Public List<Child> ChildList; } Lastly I’ve got a client and server application – I’m in control of both ends so can make changes to both programs as I need to. Client makes a request for ParentID and receives a Together Class for the matching parent, and all of the child records. The client app may make changes to the children – add new children, remove or modify existing ones. Client app then sends the Together Class back to the server app. Server app needs to update the parent and child records in the database. In addition I would like to be able to log the changes – I’m doing this by having 2 separate tables one for Parent, one for child; each containing the same columns as the original plus date time modified, by whom and a list of the changes. I’m unsure as to the best approach to detect the changes in records – new records, records to be deleted, records with no fields changed, records with some fields changed. I figure I need to read the parent & children records and compare those to the ones in the Together Class. Strategy A: If Together class’s child record has an ID of say 0, that indicates a new record; insert. Any deleted child records are no longer in the Together Class; see if any of the comparison child records are not found in the Together class and delete if not found (Compare using ID). Check each child record for changes and if changed log. Strategy B: Make a new Updated TogetherClass UpdatedClass { Public Parent Parent {get; set} Public List<Child> ListNewChild {get;set;} Public List<Child> DeletedChild {get;set;} Public List<Child> ExistingChild {get;set;} // used for no changes and modified rows } And then process as per the list. The reason why I’m asking for ideas is that both of these solutions don’t seem optimal to me and I suspect this problem has been solved already – some kind of design pattern ? I am aware of one potential problem in this general approach – that where Client App A requests a record; App B requests same record; A then saves changes; B then saves changes which may overwrite changes A made. This is a separate locking issue which I’ll raise a separate question for if I’ve got trouble implementing. The actual implementation is c#, SQL Server and WCF between client and server - sharing a library containing the class implementations. Apologies if this is a duplicate post – I tried searching various terms without finding a match though.

    Read the article

  • How to get the parent node of a given child node using PowerShell?

    - by kumar
    I am new to PowerShell. I have to write a script which can return me the first parent(node) value by passing the child node. I have the following XML. When I pass my PowerShell script the value "AAA", it should return "parent2", and when I pass "III", it should return "parent311". Can someone help me write this script? XML: <root> <parent> <parent2> <child>AAA</child> </parent2> <parent3> <child>BBB</child> <child>CCC</child> <child>DDD</child> </parent3> <parent4> <child>EEE</child> </parent4> <parent5> <child>FFF</child> </parent5> </parent> <parent21> <parent211> <child>GGG</child> </parent211> <parent311> <child>HHH</child> <child>III</child> <child>JJJ</child> </parent311> <parent411> <child>KKK</child> </parent411> <parent511> <child>LLL</child> </parent511> </parent21> </root>

    Read the article

  • ExpandableListView child items don't get focus when touched...

    - by Justin
    Ok, so I wrote an ExpandableListView and subclassed BaseExpandableListAdapter... Everything works fine except I cannot get the child views to take focus when clicked. If I use the trackball everything works fine. But if I try to click on a child I get no feedback whatsoever. I have tried setting android:focusable, android:focusableInTouchMode, and android:clickable (and I have also tried setting this via code) but I can't get anything to work. Any ideas? Here is my Adapter code: public class ExpandableAppAdapter extends BaseExpandableListAdapter { private PackageManager m_pkgMgr; private Context m_context; private List<ApplicationInfo> m_groups; private List<List<ComponentName>> m_children; public ExpandableAppAdapter(Context context, List<ApplicationInfo> groups, List<List<ComponentName>> children) { m_context = context; m_pkgMgr = m_context.getPackageManager(); m_groups = groups; m_children = children; } @Override public Object getChild(int groupPos, int childPos) { return m_children.get(groupPos).get(childPos); } @Override public long getChildId(int groupPos, int childPos) { return childPos; } @Override public int getChildrenCount(int groupPos) { return m_children.get(groupPos).size(); } @Override public View getChildView(int groupPos, int childPos, boolean isLastChild, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater inflater = LayoutInflater.from(m_context); convertView = inflater.inflate(R.layout.expandable_app_child_row, null); } ComponentName child = (ComponentName)getChild(groupPos, childPos); TextView txtView = (TextView)convertView.findViewById(R.id.item_app_pkg_name_id); if (txtView != null) txtView.setText(child.getPackageName()); txtView = (TextView)convertView.findViewById(R.id.item_app_class_name_id); if (txtView != null) txtView.setText(child.getClassName()); convertView.setFocusableInTouchMode(true); return convertView; } @Override public Object getGroup(int groupPos) { return m_groups.get(groupPos); } @Override public int getGroupCount() { return m_groups.size(); } @Override public long getGroupId(int groupPos) { return groupPos; } @Override public View getGroupView(int groupPos, boolean isExpanded, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater inflater = LayoutInflater.from(m_context); convertView = inflater.inflate(R.layout.expandable_app_group_row, null); } ApplicationInfo group = (ApplicationInfo)getGroup(groupPos); ImageView imgView = (ImageView)convertView.findViewById(R.id.item_selection_icon_id); if (imgView != null) { Drawable img = m_pkgMgr.getApplicationIcon(group); imgView.setImageDrawable(img); imgView.setMaxWidth(20); imgView.setMaxHeight(20); } TextView txtView = (TextView)convertView.findViewById(R.id.item_app_name_id); if (txtView != null) txtView.setText(m_pkgMgr.getApplicationLabel(group)); return convertView; } @Override public boolean hasStableIds() { return false; } @Override public boolean isChildSelectable(int groupPos, int childPos) { return true; } } Thanks in advance!

    Read the article

  • Simple first-child js?

    - by Glister
    Searching for a simple first-child detection via javascript (no framework). It should add some class for the first child of the element. Like a css-hacks for ie, but in javascript and for a html file. Must work similar to :first-child When I say no framework, I mean some code like this: <script type="text/javascript">document.documentElement.id = "js"</script> For example: <div class="terms"> <dl> <dt>Term 1 name</dt> <dd>Term 1 description</dd> </dl> <dl> <dt>Term 2 name</dt> <dd>Term 2 description</dd> </dl> <dl> <dt>Term 3 name</dt> <dd>Term 3 description</dd> </dl> </div> Three <dl>, the first one includes Term 1. This css won't work in IE6, thats why I'm searching for a javascript solution. CSS-hacks are not allowed. .terms dl:first-child { float: right; }

    Read the article

  • How to get child container reference in View Model

    - by niels-verkaart
    Hello, I´m trying to share a Data Service (Entity Manager) wrapped in a Repository from a ViewModel (called 'AVM') in Module A to a ViewModel (called 'BVM') in Module B, and I can't get this working. We use PRISM/Unity 2.0 This is my scenario: A user may open multiple Customer screens (composite view as mini shell) each with another customer (unit of work). We realize this using child containers. Each child container resolves it's own repository with its own Entity manager (the repository is a singleton within the child container). This is done in module A. The main shell has a main region manager, and each Customer screen with its childcontainer creates a scoped region. In each customer screen there is a View 'AV' (connected to ViewModel 'AVM') with a SubRegion (tab control) registered as 'SubRegion'. We create this with a 'Screen Factory' In Module B we have a Customer Orders in View 'BV' and ViewModel 'BVM'. In the constructor of Module B we get the main container by injection. In the initialize method we resolve the (main) region manager and register View 'BV' with it. In the constructor of View 'BV' a ViewModel 'BVM' is injected/created. Now this works, but the ViewModel 'BVM' cannot get the child container. It only get the main container. Is this doable, or do I have to do this another way? Thanks, Niels

    Read the article

  • How to terminate all [grand]child processes using C# on WXP (and newer MSWindows)

    - by NVRAM
    Question: How can I determine all processes in the child's Process Tree to kill them? I have an application, written in C# that will: Get a set of data from the server, Spawn a 3rd party utility to process the data, then Return the results to the server. This is working fine. But since a run consumes a lot of CPU and may take as long as an hour, I want to add the ability to have my app terminate its child processes. Some issues that make the simple solutions I've found elsewhere are: My app's child process "A" (InstallAnywhere EXE I think) spawns the real processing app "B" (a java.exe), which in turns spawns more children "C1".."Cn" (most of which are also written in Java). There will likely be multiple copies of my application (and hence, multiple sets of its children) running on the same machine. The child process is not in my control so there might be some "D" processes in the future. My application must run on 32-bit and 64-bit versions of MSWindows. On the plus side there is no issue of data loss, a "clean" shutdown doesn't matter as long as the processes end fairly quickly.

    Read the article

  • Communication between parent and child

    - by Pierre
    Hi every one ! I have a little problem. I have to code a simple C application that creat a process and his child (fork()) and I have to do an operation. Parent initialize the values and child calculate. I write this : #include #include #include #include #include typedef struct { int op1; char op; int op2; }Operation; Operation *varOP; void finalResult() { float result = 0; if(varOP-op == '+') result = (varOP-op1 + varOP-op2); if(varOP-op == '-') result = (varOP-op1 - varOP-op2); if(varOP-op == '*') result = (varOP-op1 * varOP-op2); if(varOP-op == '+') result = (varOP-op1 / varOP-op2); printf("%f",result); } int main () { int p; varOP = (Operation *)malloc(sizeof(Operation)); p = fork(); if(p == 0) // If child { signal(SIGUSR1, finalResult ); pause(); } if(p 0) // If parent { varOP-op = '+'; varOP-op1 = 2; varOP-op2 = 3; kill(p, SIGUSR1); wait(NULL); } return 0; } But my child is never called. Is there something wrong with my code? Thanks for your help !

    Read the article

  • :first-child fails when an element of a different class is dynamically inserted above

    - by koko
    So, I've encountered a situation where inserting an element of a different class/id breaks all css-rules on that :first-child. <div id="nav"> <div class="nSub">abcdef</div> <div class="nSub">abcdef</div> <div class="nSub">abcdef</div> <div class="nSub">abcdef</div> <div class="nSub">abcdef</div> </div> .nSub:first-child { margin-top:15px; -moz-border-radius-topleft:5px; /* ... */ } .nSub { background:#666; /* ... */ } .nSub:last-child { -moz-border-radius-bottomleft:5px; /* ... */ } As soon as I insert an element of another class/id above, like this: $('nav').insert({top:'<div id="newWF"></div>'}); all declarations for .nSub:first-child are being ignored in both FF 3.6 and Safari 4.

    Read the article

  • Python's subprocess.Popen object hangs gathering child output when child process does not exit

    - by Daniel Miles
    When a process exits abnormally or not at all, I still want to be able to gather what output it may have generated up until that point. The obvious solution to this example code is to kill the child process with an os.kill, but in my real code, the child is hung waiting for NFS and does not respond to a SIGKILL. #!/usr/bin/python import subprocess import os import time import signal import sys child_script = """ #!/bin/bash i=0 while [ 1 ]; do echo "output line $i" i=$(expr $i \+ 1) sleep 1 done """ childFile = open("/tmp/childProc.sh", 'w') childFile.write(child_script) childFile.close() cmd = ["bash", "/tmp/childProc.sh"] finish = time.time() + 3 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) while p.poll() is None: time.sleep(0.05) if finish < time.time(): print "timed out and killed child, collecting what output exists so far" out, err = p.communicate() print "got it" sys.exit(0) In this case, the print statement about timing out appears and the python script never exits or progresses. Does anybody know how I can do this differently and still get output from my child processe

    Read the article

  • Foreign key not stored in child entity (one-to-many)

    - by Kamil Los
    Hi, I'm quite new to hibernate and have stumbled on this problem, which I can't find solution for. When persisting parent object (with one-to-many relationship with child), the foreign-key to this parent is not stored in child's table. My classes: Parent.java @javax.persistence.Table(name = "PARENT") @Entity public class PARENT { private Integer id; @javax.persistence.Column(name = "ID") @Id @GeneratedValue(strategy=GenerationType.AUTO) public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } private Collection<Child> children; @OneToMany(mappedBy = "parent", fetch = FetchType.EAGER, cascade = {CascadeType.ALL}) @Cascade({org.hibernate.annotations.CascadeType.ALL}) public Collection<Child> getChildren() { return children; } public void setChildren(Collection<Child> children) { this.children = children; } } Child.java @javax.persistence.Table(name = "CHILD") @Entity @IdClass(Child.ChildId.class) public class Child { private String childId1; @Id public String getChildId1() { return childId1; } public void setChildId1(String childId1) { this.childId1 = childId1; } private String childId2; @Id public String getChildId2() { return childId2; } public void setChildId2(String childId2) { this.childId2 = childId2; } private Parent parent; @ManyToOne @javax.persistence.JoinColumn(name = "PARENT_ID", referencedColumnName = "ID") public Parent getParent() { return parent; } public void setParent(Operation parent) { this.parent = parent; } public static class ChildId implements Serializable { private String childId1; @javax.persistence.Column(name = "CHILD_ID1") public String getChildId1() { return childId1; } public void setChildId1(String childId1) { this.childId1 = childId1; } private String childId2; @javax.persistence.Column(name = "CHIILD_ID2") public String getChildId2() { return childId2; } public void setChildId2(String childId2) { this.childId2 = childId2; } public ChildId() { } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ChildId that = (ChildId) o; if (childId1 != null ? !childId1.equals(that.childId1) : that.childId1 != null) return false; if (childId2 != null ? !childId2.equals(that.childId2) : that.childId2 != null) return false; return true; } @Override public int hashCode() { int result = childId1 != null ? childId1.hashCode() : 0; result = 31 * result + (childId2 != null ? childId2.hashCode() : 0); return result; } } } Test.java public class Test() { private ParentDao parentDao; public void setParentDao(ParentDao parentDao) { this.parentDao = parentDao; } private ChildDao childDao; public void setChildDao(ChildDao childDao) { this.childDao = parentDao; } test1() { Parent parent = new Parent(); Child child = new Child(); child.setChildId1("a"); child.setChildId2("b"); ArrayList<Child> children = new ArrayList<Child>(); children.add(child); parent.setChildren(children); parent.setValue("value"); parentDao.save(parent); //calls hibernate's currentSession.saveOrUpdate(entity) } test2() { Parent parent = new Parent(); parent.setValue("value"); parentDao.save(parent); //calls hibernate's currentSession.saveOrUpdate(entity) Child child = new Child(); child.setChildId1("a"); child.setChildId2("b"); child.setParent(parent); childDao.save(); //calls hibernate's currentSession.saveOrUpdate(entity) } } When calling test1(), both entities get written to database, but field PARENT_ID in CHILD table stays empty. The only workaround I have so far is test2() - persisting parent first, and then the child. My goal is to persist parent and its children in one call to save() on Parent. Any ideas?

    Read the article

  • Debugging nth-child selector

    - by Ross
    I have the following selectors: .progress:nth-child(3n+1) { background: teal; } .progress:nth-child(3n+2) { background: red; } .progress:nth-child(3n+3) { background: blue; } However all of the items end up with a teal background. Are these selectors correct? I'm thinking I should get: Teal (every 3, starting with 1) Red (every 3, starting with 2) Blue (every 3, starting with 3) etc. I've tested on Firefox 3.5.8 and Opera 10.10 on Ubuntu. Also tested with nothing but these rules in the CSS. I'm using the YUI Reset stylesheet but excluding it does nothing.

    Read the article

  • Creating a child process on Unix systems?

    - by Hakan Svensson
    I'm trying to create a child process in another process. I am writing both the programs in C language. First I write a dummy process which will be the child process. What it is doing is only to write a string on the screen. It works well on its own. Then I write another program which will be the parent process. However, I can't make it happen. I'm trying to use fork and execl functions together, but I fail. I also want the child process does not terminate until the parent process terminates. How should I write the parent process? Thanks.

    Read the article

  • Run shell command from child shell

    - by LinuxPenseur
    Hi, I have a Unix shell script test.sh. Within the script i would like to invoke another shell and then execute the rest of the commands in the shell script from the child shell and exit To make it clear: test.sh #! /bin/bash /bin/bash /* create child shell */ <shell-command1> <shell-command2> ...... <shell-commandN> exit 0 What my intention is to run the shell-commands1 to shell-commandN from the child shell. Kindly tell me how to do this

    Read the article

  • AS3 Accessing Variables of Parent Class From Child

    - by TheDarkIn1978
    i'm trying to assign a parent's variable from the parent's child //Parent public class Main extends Sprite { public var selectedSquare:Sprite; public function Main() { //inits and adds new Square child class to display list } ... ------- //Child public function dragSquare(evt:MouseEvent):void { Sprite(parent).selectedSquare = this; //evil doesn't work! parent.addChild(this); this.startDrag(); } i'm receiving this error, but i'm casting parent from displayObjectContainer to a Sprite so i have no idea why it's not working. 1119: Access of possibly undefined property selectedSquare through a reference with static type flash.display:Sprite.

    Read the article

  • Problem installing wordpress child themes.

    - by Jay
    Hi, I've tried to install either the Fusion or Thematic child themes for my blog. My Wordpress directory is located at myblog/wordpress while my domain is just myblog (example). Everything works fine with both basic themes or the parent Fusion or Thematic themes. When I install a child theme for either framework, I can view the preview and select 'activate.' However, after that my entire site crashes. I can't even view the wordpress admin panel. I've had to restore my database from my hosting provider just to get my blog working. All that I'm able to see is my favicon icon and a blank page. I've tried to deactivate all plugins and this doesn't help either. I really want to use the Hybrid News child template. Any thoughts on what might be happening? thanks so much!

    Read the article

  • TSQL Cascade delete for child records?

    - by ElHaix
    I have a parent/child table (simple tree) table structure (ID, ParentID), where I want to delete (and get the ID of) all children for a given parent ID - similar to this post http://stackoverflow.com/questions/1433808/sql-server-cascade-delete-and-parent-child-table . During the loop, where I've got the current ID, I will also be performing other actions with this ID. Can someone give me an example of the SPROC to accomplish this? Thanks

    Read the article

  • current page highlights on child pages

    - by user557318
    Im trying to achieve current page highlights on wordpress similar to this site Alex Soth. I'm very nearly there with my css. At present i have current page highlights on pages, ie. home,calendar, projects. However when it come to current page highlights on child pages i have a problem. the indented child page list appears on hover when selecting a child page, but after page selection the menu reverts back to the standard pages menu with no visible child menus? unlike the link to the Alex Soth site where the extended menu stays and current page is highlighted I know that the answer will be a simple piece of css involving current_page_item and possible position:relative to obtain the menu staying visible after selection. But i can for the life of me work it out. Any ideas Ive attached my relivant pieces of css below?? thanks /* =Link Styles ------------------------------------------------------------------*/ input#submit { cursor: pointer; } input#searchsubmit { background: url(images/search.png) no-repeat center; } input#searchsubmit:hover { background: url(images/search.png) no-repeat center #3399FF !important; cursor: pointer; } .navigation a:hover, input#submit { background: #3399FF; color: #3399FF !important; } a { color: #666; } a:hover, a:hover span { color: #c11501 !important;background-color: #fae100; } .entry sup a, #main_nav .current_page_item a, #main_nav .current_page_ancestor a { color: #666 !important; } #main_nav h1.masthead a { color: #666; } #main_nav h1.masthead a:hover { border-right: none; } h2 a, #main_nav a { color: #3399FF; } img a, img a:hover { text-decoration: none; } .post a, .navigation a { font-weight: bold; color: #000; } .navigation a { background: #EEE; color: #666; font-weight: normal; padding: 3px 0px; border-radius: 0px; -webkit-border-radius: 0px; -moz-border-radius: 0px; } .post sup { font-size: 11px; color: #aaa; } .post sup a { border: 0; margin: 0; font-weight: normal; font-size: 10px; } #supplementary .post_nav ul.about_nav li a, #supplementary .post_nav ul.single_post_meta a, #supplementary ul.contact_key li a { color: #888888; border-bottom: 0; } /* =Main Menu ------------------------------------------------------------------*/ #main_nav ul.menu li { position: relative; } #main_nav ul.menu li:hover ul.sub-menu, #main_nav ul.menu li:hover ul.children { display: block; }

    Read the article

  • C#/.NET Little Wonders: The Nullable static class

    - by James Michael Hare
    Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. Today we’re going to look at an interesting Little Wonder that can be used to mitigate what could be considered a Little Pitfall.  The Little Wonder we’ll be examining is the System.Nullable static class.  No, not the System.Nullable<T> class, but a static helper class that has one useful method in particular that we will examine… but first, let’s look at the Little Pitfall that makes this wonder so useful. Little Pitfall: Comparing nullable value types using <, >, <=, >= Examine this piece of code, without examining it too deeply, what’s your gut reaction as to the result? 1: int? x = null; 2:  3: if (x < 100) 4: { 5: Console.WriteLine("True, {0} is less than 100.", 6: x.HasValue ? x.ToString() : "null"); 7: } 8: else 9: { 10: Console.WriteLine("False, {0} is NOT less than 100.", 11: x.HasValue ? x.ToString() : "null"); 12: } Your gut would be to say true right?  It would seem to make sense that a null integer is less than the integer constant 100.  But the result is actually false!  The null value is not less than 100 according to the less-than operator. It looks even more outrageous when you consider this also evaluates to false: 1: int? x = null; 2:  3: if (x < int.MaxValue) 4: { 5: // ... 6: } So, are we saying that null is less than every valid int value?  If that were true, null should be less than int.MinValue, right?  Well… no: 1: int? x = null; 2:  3: // um... hold on here, x is NOT less than min value? 4: if (x < int.MinValue) 5: { 6: // ... 7: } So what’s going on here?  If we use greater than instead of less than, we see the same little dilemma: 1: int? x = null; 2:  3: // once again, null is not greater than anything either... 4: if (x > int.MinValue) 5: { 6: // ... 7: } It turns out that four of the comparison operators (<, <=, >, >=) are designed to return false anytime at least one of the arguments is null when comparing System.Nullable wrapped types that expose the comparison operators (short, int, float, double, DateTime, TimeSpan, etc.).  What’s even odder is that even though the two equality operators (== and !=) work correctly, >= and <= have the same issue as < and > and return false if both System.Nullable wrapped operator comparable types are null! 1: DateTime? x = null; 2: DateTime? y = null; 3:  4: if (x <= y) 5: { 6: Console.WriteLine("You'd think this is true, since both are null, but it's not."); 7: } 8: else 9: { 10: Console.WriteLine("It's false because <=, <, >, >= don't work on null."); 11: } To make matters even more confusing, take for example your usual check to see if something is less than, greater to, or equal: 1: int? x = null; 2: int? y = 100; 3:  4: if (x < y) 5: { 6: Console.WriteLine("X is less than Y"); 7: } 8: else if (x > y) 9: { 10: Console.WriteLine("X is greater than Y"); 11: } 12: else 13: { 14: // We fall into the "equals" assumption, but clearly null != 100! 15: Console.WriteLine("X is equal to Y"); 16: } Yes, this code outputs “X is equal to Y” because both the less-than and greater-than operators return false when a Nullable wrapped operator comparable type is null.  This violates a lot of our assumptions because we assume is something is not less than something, and it’s not greater than something, it must be equal.  So keep in mind, that the only two comparison operators that work on Nullable wrapped types where at least one is null are the equals (==) and not equals (!=) operators: 1: int? x = null; 2: int? y = 100; 3:  4: if (x == y) 5: { 6: Console.WriteLine("False, x is null, y is not."); 7: } 8:  9: if (x != y) 10: { 11: Console.WriteLine("True, x is null, y is not."); 12: } Solution: The Nullable static class So we’ve seen that <, <=, >, and >= have some interesting and perhaps unexpected behaviors that can trip up a novice developer who isn’t expecting the kinks that System.Nullable<T> types with comparison operators can throw.  How can we easily mitigate this? Well, obviously, you could do null checks before each check, but that starts to get ugly: 1: if (x.HasValue) 2: { 3: if (y.HasValue) 4: { 5: if (x < y) 6: { 7: Console.WriteLine("x < y"); 8: } 9: else if (x > y) 10: { 11: Console.WriteLine("x > y"); 12: } 13: else 14: { 15: Console.WriteLine("x == y"); 16: } 17: } 18: else 19: { 20: Console.WriteLine("x > y because y is null and x isn't"); 21: } 22: } 23: else if (y.HasValue) 24: { 25: Console.WriteLine("x < y because x is null and y isn't"); 26: } 27: else 28: { 29: Console.WriteLine("x == y because both are null"); 30: } Yes, we could probably simplify this logic a bit, but it’s still horrendous!  So what do we do if we want to consider null less than everything and be able to properly compare Nullable<T> wrapped value types? The key is the System.Nullable static class.  This class is a companion class to the System.Nullable<T> class and allows you to use a few helper methods for Nullable<T> wrapped types, including a static Compare<T>() method of the. What’s so big about the static Compare<T>() method?  It implements an IComparer compatible comparison on Nullable<T> types.  Why do we care?  Well, if you look at the MSDN description for how IComparer works, you’ll read: Comparing null with any type is allowed and does not generate an exception when using IComparable. When sorting, null is considered to be less than any other object. This is what we probably want!  We want null to be less than everything!  So now we can change our logic to use the Nullable.Compare<T>() static method: 1: int? x = null; 2: int? y = 100; 3:  4: if (Nullable.Compare(x, y) < 0) 5: { 6: // Yes! x is null, y is not, so x is less than y according to Compare(). 7: Console.WriteLine("x < y"); 8: } 9: else if (Nullable.Compare(x, y) > 0) 10: { 11: Console.WriteLine("x > y"); 12: } 13: else 14: { 15: Console.WriteLine("x == y"); 16: } Summary So, when doing math comparisons between two numeric values where one of them may be a null Nullable<T>, consider using the System.Nullable.Compare<T>() method instead of the comparison operators.  It will treat null less than any value, and will avoid logic consistency problems when relying on < returning false to indicate >= is true and so on. Tweet   Technorati Tags: C#,C-Sharp,.NET,Little Wonders,Little Pitfalls,Nulalble

    Read the article

  • Finding nth-child of siblings via jQuery

    - by DA
    Let's say I have two tables that look like this: TH TH TH TH TD TD TD TD TD TD TD TD and TH TH TH TH TH TD TD TD TH TD TD TD I'd like to select the 3rd column in each. At first I was using nth-child as such: $('table tr td:nth-child(3)') But that's not going to work, as 3rd TD is in a different column in each table. What I need in pseudo code is 'get the 3rd TD or TH in each row'. I assume I need to use $.siblings but not entirely sure.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >