Opened 11 years ago

Closed 11 years ago

#7379 closed enhancement (wontfix)

[patch][cla] first, last methods on NodeList

Reported by: Sam Foster Owned by: dante
Priority: low Milestone: future
Component: Dojox Version: 1.1.1
Keywords: Cc:
Blocked By: Blocking:

Description

This is mostly sugar, but I find a frequent pattern is wanting to use dojo.query to apply a function to the first/last element matching some css selector. But without a guarantee that the query will match you have to check the nodelist length before accessing properties on the first item - a pain.

Attachments (1)

nodelist-first.patch (1.8 KB) - added by Sam Foster 11 years ago.
[PATCH] [CLA] adds a dojo-ext top-level dir to dojox, and a Nodelist.js which defines a first, last method

Download all attachments as: .zip

Change History (6)

Changed 11 years ago by Sam Foster

Attachment: nodelist-first.patch added

[PATCH] [CLA] adds a dojo-ext top-level dir to dojox, and a Nodelist.js which defines a first, last method

comment:1 Changed 11 years ago by Sam Foster

I've got the first/last methods returning the NodeList?, so you could have e.g.:

dojo.query(".foo").first(function(n){ something... }).last(function(n) { something else }).etc...

So, its not overlapping with Nodelist.at(), nor is it the same as dojo.query("whatever:first-child"). The value I'm trying to add here is to avoid this:

/* get my element */
var nodes = dojo.query(".some > query"); 
if(nodes.length) { 
  doSomething(nodes[0]); 
}

Its admittedly of marginal value, but its also next to no code, and I think makes for more fluid (user) code.

comment:2 Changed 11 years ago by Adam Peller

Cc: dante added
Milestone: tbd1.3
Summary: first, last methods on NodeList[patch][cla] first, last methods on NodeList

comment:3 Changed 11 years ago by Adam Peller

Cc: dante removed
Owner: changed from Adam Peller to dante

Pete, this one should probably belong to you...

comment:4 Changed 11 years ago by dante

Milestone: 1.3future
Priority: normallow
Status: newassigned

so I'd love to see the ext-dojo namespace exist and be fun, but it's not practical at the moment. I'm going to put these minimal sized functions in plugd and doc them as time permits, and give them that clear migration path into dojo should the api be agreed upon. moving to 'future' for now, but just means I'll close when the code is in plugd and more prepared for merging.

comment:5 Changed 11 years ago by dante

Resolution: wontfix
Status: assignedclosed

added to plugd r26. closing this ticket wontfix. We can decide later if any of base plugd code should be promoted and doc at leisure this way. (all plugd stuff is CLA'd to foundation)

Note: See TracTickets for help on using tickets.