RJS 语法备注(zz)

1<<(javascript) page写原生的JavaScript代码。

2[](id) 返回通过idDOM内找到的一个元素引用。然后可在以后方法调用中使用这个元素。例如:

page['blank_slate'] # => $('blank_slate');

page['blank_slate'].show # => $('blank_slate').show();

page['blank_slate'].show('first').up # => $('blank_slate').show('first').up();

3alert(message) 用给定信息显示一个警告对话框。

4assign(variable, value) 获取一个变量名和值,创建一个本地JavaScript代码块,并将该值赋予该对象。

5call(function, *arguments) 获取一个函数名和一组参数,创建一个调用该函数的本地JavaScript调用,并传入相应的参数。

6delay(seconds = 1) {| | ...} 在指定秒延时后运行块的内容。创建一个JavaScript代码块,在执行之前等待相应秒数。

例如:

page.delay(20) do

page.visual_effect :fade, 'notice'

end

7draggable(id, options = {}) 创建一个script.aculo.us draggable 元素。查阅ActionView::Helpers::ScriptaculousHelper

8drop_receiving(id, options = {}) 创建一个 script.aculo.us drop receiving 元素。查阅ActionView::Helpers::ScriptaculousHelper

9hide(*ids) 隐藏指定id的可见的DOM元素。使用PrototypeElement.hide

10insert_html(position, id, *options_for_render)

在由id给出的DOM元素的相对位置上插入HTML position 的值可以是:

:top HTML 被插入到元素现有内容的前面。

:bottom HTML 被插入到元素现有内容的后面。

:before HTML 被插入到元素的前面。

:after HTML 被插入到元素的后面。

options_for_render 即可以是字符串也可以是插入的HTML,或者是传递给ActionView::Base#render的选项哈希表。

例如:

# Insert the rendered 'navigation' partial just before the DOM

# element with ID 'content'.

insert_html :before, 'content', :partial => 'navigation'

# Add a list item to the bottom of the <ul> with ID 'list'.

insert_html :bottom, 'list', '<li>Last item</li>'

11redirect_to(location) 重定向浏览器到指定位置,格式同url_for。并将其传给window.location.href

12remove(*ids) 从页中移除指定idDOM元素。使用PrototypeElement.remove

13replace(id, *options_for_render) 替换给定idDOM元素的"outer HTML" (即,是整个元素,而不只是它的内容) 使用PrototypeElement.replace

options_for_render即可以是字符串也可以是插入的HTML,或者是传递给ActionView::Base#render的选项哈希表。

例如:

# Replace the DOM element having ID 'person-45' with the

# 'person' partial for the appropriate object.

replace_html 'person-45', :partial => 'person', :object => @person

This allows the same partial that is used for the insert_html to be also used for the input to replace without resorting to the use of wrapper elements.

例如:

<div id="people">

<%= render :partial => 'person', :collection => @people %>

</div>

# Insert a new person

page.insert_html :bottom, :partial => 'person', :object => @person

# Replace an existing person

page.replace 'person_45', :partial => 'person', :object => @person

14replace_html(id, *options_for_render) 替换给定idDOM元素的inner HTML 使用PrototypeElement.update

options_for_render即可以是字符串也可以是插入的HTML,或者是传递给ActionView::Base#render的选项哈希表。

例如:

# Replace the HTML of the DOM element having ID 'person-45' with the

# 'person' partial for the appropriate object.

replace_html 'person-45', :partial => 'person', :object => @person

15select(pattern) 返回DOM内符合CSS模式的元素引用集合。可以在将来的方法调用中使用此集合。

例如:

page.select('p') # => $$('p');

page.select('p.welcome b').first # => $$('p.welcome b').first();

page.select('p.welcome b').first.hide # => $$('p.welcome b').first().hide();

You can also use prototype enumerations with the collection. Observe:

page.select('#items li').each do |value|

value.hide

end

# => $$('#items li').each(function(value) { value.hide(); });

Though you can call the block param anything you want, they are always rendered in the javascript as ‘value, index.’ Other enumerations, like collect() return the last statement:

page.select('#items li').collect('hidden') do |item|

item.hide

end

# => var hidden = $$('#items li').collect(function(value, index) { return value.hide(); });

16show(*ids) 显示指定id的,被隐藏的DOM元素。使用PrototypeElement.show

17sortable(id, options = {}) Creates a script.aculo.us sortable element. Useful to recreate sortable elements after items get added or deleted.

See ActionView::Helpers::ScriptaculousHelper for more information.

18toggle(*ids) 切换指定idDOM元素的可见性。使用PrototypeElement.toggle

19visual_effect(name, id = nil, options = {}) 启动script.aculo.us 的一个可视效果。查阅ActionView::Helpers::ScriptaculousHelper

posted on 2008-03-01 11:49  Snowwolf  阅读(293)  评论(0编辑  收藏  举报

导航