DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> AJAX入門 >> AJAX詳解 >> Rails的RJS模板十
Rails的RJS模板十
編輯:AJAX詳解     

4、remote_function(options)

生成 JavaScript 來產生一個後台AJax 請求給一個遠程的控制器動作。這個方法對從DOM對象的事件處理程序生成AJax調用是很有用的,比如 tag. Takes the same options as link_to_remote().

5、observe_form(form_id, options = {})

工作類似於 observe_fIEld(),但觀察的是整個表單。

Works just like observe_fIEld(), but observes an entire form.

6、form_remote_tag(options = {})

創建一個 form 標記,它使用後台AJax請求來遞交表單的內容。這是生成AJax請求的又一個非常常見的方式。

Creates a form tag that submits the contents of the form using a background AJax request. This is another very common way to makeAJax requests.

7、form_remote_for(object_name, object, options = {}, &proc)

類似於 form_remote_tag(),但是使用與Rails1.1引入 form_for語義。

Just like form_remote_tag(), but uses the form_for semantics introduced in Rails 1.1.

8、submit_to_remote(name, value, options = {})

創建一個按鈕,它將遞交父表單的內容給遠程控制器動作。選項與form_remote_tag() 一樣。

Creates a button that will submit the contents of the parent form to the remote controller action. The options are the same as for form_remote_tag().

9、in_place_editor_fIEld(object, method, tag_options = {}, in_place_editor_options = {})

當被修改的字段被提交時生成一個AJax請求。要同RJS使用該方法,你必須在選項內傳遞 :script => true 給 in_place_editor_options hash。

Makes an AJax request when changes to the fIEld are committed. To use this method with RJS you have to pass in the option :script => true to the in_place_editor_options hash.

10、in_place_editor(fIEld_id, options = {})

這個方法是對 in_place_editor_fIEld() 的包裝。要與RJS使用這個方法你需要在選項 hash 內傳遞 :script => true。

This is the method that the in_place_editor_fIEld() wraps. To use this method with RJS you need to pass in the :script => true option to the options hash.

11、drop_receiving_element(element_id, options = {})

當可拖放元素被放到元素上時生成一個AJax請求。

Makes an AJax request when droppable elements are dropped onto the element.

12、sortable_element(element_id, options = {})

只要這個元素被排序則生成一個AJax請求。

An AJax request is made whenever this element is sorted using drag and drop.

13、AJax.Request(url, options)

所有Rails輔助方法使用這個Ptototype對象來產生實際的AJax請求,你也可以使用這個對象來從你的JavaScript庫生成遠程AJax請求。這是一個JavaScript對象不是Ruby對象。

All Rails helpers use this Prototype object to make the actual AJaxrequests. You can also use this object to make remote AJax requests from your Javascript librarIEs. This is a JavaScript object and not a Ruby object.

第四節 Helpers – 輔助方法

Rails輔助方法可以被使用在RJS模板內以分組多個page操作到一個方法內。傳統的輔助方法與RJS輔助方法的唯一區別是RJS輔助方法必須使用暗中有效的 page 對象。

Rails helpers can be used within RJS templates to group multiple page Operations into one method. The only difference between traditional helpers and RJS helpers is that RJS helpers must make use of the implicitly available page object.

def insert_item(list_id, item)

page.insert_Html :bottom, list_id, '

  • #{item.title}
  • '

    page.visual_effect :highlight, 'item_#{item.id}', :duration => 0.5

    end

    現在,與總是在每個模板內調用insert_Html()與visual_effect()相反,我們可以只調用方法insert_item(),它會讓模板更簡單,更易閱讀。新的輔助方法可以像下面從一個RJS模板內調用,那兒的@item是一個對RJS模板有效的實例變量,並且my_list是我們想附加給item的無序列表:

    Now, instead of always calling insert_Html() and visual_effect() in every template, we can just call the method insert_item(), which will make for simpler, more readable templates. The new helper method can be called from an RJS template as follows, where @item is an instance variable available to the RJS template and my_list is the unordered list we want to append the item to:

    page.insert_item 'my_list', @item

    XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
    Copyright © DIV+CSS佈局教程網 All Rights Reserved