Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
{div:class=} h1.
Wiki Markup
Div
classapi-page

fluid.find(list,

fn,

deflt)

{section} {column:width=70%} Scans through a list of objects, terminating on and returning the first member which matches a predicate function. {code:javascript|borderStyle=none|bgColor=white}

Section
Column
width70%

Scans through a list of objects, terminating on and returning the first member which matches a predicate function.

Code Block
javascript
bgColorwhite
borderStylenone
javascript

fluid.find(list, fn, deflt);
{code} *File

File name:

* {{

Fluid.js

}} h2. Parameters {span:class=

Parameters

Span
classborderless-table

} |*{{source}}*|

source

(Arrayable

\

|

Object)

The

list

or

hash

of

objects

to

be

searched.

| |*{{fn}}*|

fn

(Function)

A

predicate

function,

acting

on

a

list

member.

A

predicate

which

returns

any

value

which

is

not

{{

null

}}

or

{{

undefined

}}

will

terminate

the

search.

The

function

has

the

signature

(object,

index).

| |*{{deflt}}*|

deflt

(Object)

(optional)

A

value

to

be

returned

in

the

case

no

predicate

function

matches

a

list

member.

The

default

will

be

the

natural

value

of

{{undefined}} | {span} h2. Return Value {span:class=borderless-table} |*Object*| the first object in the list that matches the predicate function, or {{deflt}} if nothing does | {span} {column} {column:width=5%} {column} {column} h3. See Also {column} {section} ---- h3. Example {code:javascript}

undefined

Return Value

Span
classborderless-table

Object

the first object in the list that matches the predicate function, or deflt if nothing does

Column
width5%

Column

See Also


Example

Code Block
javascript
javascript

var findColIndex = function (item, layout) {
    return fluid.find(layout.columns,
                      function (column, colIndex) {
                          return item === column.container? colIndex : undefined;
                      });
};
{code}

The

function

{{

findColIndex

}}

uses

{{

fluid.find

}}

to

examine

a

list

of

columns.

The

anonymous

function

being

passed

as

the

second

argument

compares

each

column's

{{

container

}}

property

against

the

desired

{{

item

}}

and

returns

the

index

of

the

column

if

it

matches.

{{

fluid.find

}}

will

apply

this

function

to

each

item

in

the

column

list

and

return

the

first

column

that

matches.

{div}