RJS参考之JavaScriptCollectionProxy

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值