JavaScriptGenerator#select()返回一个JavaScriptElementCollectionProxy类的实例,它继承于JavaScriptCollectionProxy。
JavaScriptCollectionProxy有一些方法:
[code]
all(variable) {|value,index| block }
[/code]
Each element is passed to the block. The block is converted to a JavaScript iterator function. The JavaScript variable is set to TRue if the iterator function never returns false or null.
[code]
any(variable){|value, index| block }
[/code]
Each element is passed to the block. The block is converted to a JavaScript iterator function. The JavaScript variable is set to TRue if the iterator function never returns false or null.
[code]
collect(variable){|value, index| block }
[/code]
The block is converted to a JavaScript iterator. This method assigns a new JavaScript Array to the JavaScript variable containing the results of executing the iterator function once for each element.
[code]
detect(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function. The JavaScript variable is assigned to the first element for which the iterator function does not return false.
[code]
each{|value, index| block }
[/code]
Passes each element to the block, which is converted to a JavaScript iterator function. The iterator function is called once for each element.
[code]
find(variable){|value, index| block }
[/code]
A synonym for JavaScriptCollectionProxy#detect().
[code]
find_all(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function. The JavaScript variable is assigned to an Array of all elements for which the iterator function does not return false.
[code]
grep(variable, pattern){|value, index| block }
[/code]
Each DOM element with a toString() matching the Regexp pattern is passed to the given block. The block is converted to a JavaScript iterator function. The JavaScript variable is assigned to an Array containing the results of executing the iterator function once for each element.
This method isn't entirely useful in the context of RJS. Its only real use is matching DOM elements using the pattern based on their type, which is output by the toString() method. The toString() method outputs [object HTMLDivElement] for a <div> element. Use the FireBug console to view the toString() output for other elements.
[code]
inject(variable, memo){|memo, value, index| block }
[/code]
Each element and the accumulator value memo is passed to the given block. The block is converted to a JavaScript iterator function. The iterator function is called once for each element and the result is stored in memo. The result returned to the JavaScript variable is the final value of memo. The initial value of memo is set in one of two ways. The value of the parameter memo is used as the initial value if a non nil value is passed in to the method. Otherwise, the first element of the collection is used as the initial value.
[code]
map(variable){|value, index| block }
[/code]
Synonym for JavaScriptCollectionProxy#collect().
[code]
max(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function. The JavaScript variable is assigned to the largest value returned by the iterator function.
[code]
min(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function. The JavaScript variable is assigned to the smallest value returned by the iterator function.
[code]
partition(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function and is executed once for each element. The JavaScript variable is set to an Array containing to Arrays. The first Array contains all of the elements for which the iterator function evaluated to true. The second Array contains all of the remaining elements.
[code]
pluck(variable, property)
[/code]
Iterates through the collection creating a new Array from the value of the given property of each object without a function call. The resulting Array is assigned to the JavaScript variable.
[code]
reject(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function. The JavaScript variable is assigned to an Array of all elements for which the iterator function returns false.
[code]
select(variable){|value, index| block }
[/code]
A synonym for JavaScriptCollectionProxy#find_all().
[code]
sort_by(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function. Assigns the JavaScript variable to an Array of the elements sorted using the result of the iterator function as keys for the comparisons when sorting.
[code]
zip(variable, arg1, ...){|value, index| block }
[/code]
Merges elements with the arrays passed as parameters. Elements in the corresponding index of each array form a new array. The resulting array of arrays is assigned to the JavaScript variable. If a block is provided it is converted to an iterator function and is applied to each resulting Array. The name of the parameter to the iterator function is array.
JavaScriptCollectionProxy有一些方法:
[code]
all(variable) {|value,index| block }
[/code]
Each element is passed to the block. The block is converted to a JavaScript iterator function. The JavaScript variable is set to TRue if the iterator function never returns false or null.
[code]
any(variable){|value, index| block }
[/code]
Each element is passed to the block. The block is converted to a JavaScript iterator function. The JavaScript variable is set to TRue if the iterator function never returns false or null.
[code]
collect(variable){|value, index| block }
[/code]
The block is converted to a JavaScript iterator. This method assigns a new JavaScript Array to the JavaScript variable containing the results of executing the iterator function once for each element.
[code]
detect(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function. The JavaScript variable is assigned to the first element for which the iterator function does not return false.
[code]
each{|value, index| block }
[/code]
Passes each element to the block, which is converted to a JavaScript iterator function. The iterator function is called once for each element.
[code]
find(variable){|value, index| block }
[/code]
A synonym for JavaScriptCollectionProxy#detect().
[code]
find_all(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function. The JavaScript variable is assigned to an Array of all elements for which the iterator function does not return false.
[code]
grep(variable, pattern){|value, index| block }
[/code]
Each DOM element with a toString() matching the Regexp pattern is passed to the given block. The block is converted to a JavaScript iterator function. The JavaScript variable is assigned to an Array containing the results of executing the iterator function once for each element.
This method isn't entirely useful in the context of RJS. Its only real use is matching DOM elements using the pattern based on their type, which is output by the toString() method. The toString() method outputs [object HTMLDivElement] for a <div> element. Use the FireBug console to view the toString() output for other elements.
[code]
inject(variable, memo){|memo, value, index| block }
[/code]
Each element and the accumulator value memo is passed to the given block. The block is converted to a JavaScript iterator function. The iterator function is called once for each element and the result is stored in memo. The result returned to the JavaScript variable is the final value of memo. The initial value of memo is set in one of two ways. The value of the parameter memo is used as the initial value if a non nil value is passed in to the method. Otherwise, the first element of the collection is used as the initial value.
[code]
map(variable){|value, index| block }
[/code]
Synonym for JavaScriptCollectionProxy#collect().
[code]
max(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function. The JavaScript variable is assigned to the largest value returned by the iterator function.
[code]
min(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function. The JavaScript variable is assigned to the smallest value returned by the iterator function.
[code]
partition(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function and is executed once for each element. The JavaScript variable is set to an Array containing to Arrays. The first Array contains all of the elements for which the iterator function evaluated to true. The second Array contains all of the remaining elements.
[code]
pluck(variable, property)
[/code]
Iterates through the collection creating a new Array from the value of the given property of each object without a function call. The resulting Array is assigned to the JavaScript variable.
[code]
reject(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function. The JavaScript variable is assigned to an Array of all elements for which the iterator function returns false.
[code]
select(variable){|value, index| block }
[/code]
A synonym for JavaScriptCollectionProxy#find_all().
[code]
sort_by(variable){|value, index| block }
[/code]
Each element is passed to the given block. The block is converted to a JavaScript iterator function. Assigns the JavaScript variable to an Array of the elements sorted using the result of the iterator function as keys for the comparisons when sorting.
[code]
zip(variable, arg1, ...){|value, index| block }
[/code]
Merges elements with the arrays passed as parameters. Elements in the corresponding index of each array form a new array. The resulting array of arrays is assigned to the JavaScript variable. If a block is provided it is converted to an iterator function and is applied to each resulting Array. The name of the parameter to the iterator function is array.