打印

[标准问题] 老贴新问

老贴新问

今天翻看了下以前大家发的贴子,有个贴子中有这么个方法
def display(elements, params)
  # elements is an array of element ids, usually divs
  render(:update) { |page|
  @params = params
# If a view calls a helper, it looses access to the params of this block
# However it continues to have access to this block's instance variables
  if elements.include?("items")
   page.replace_html "items", :partial =>"items/items"
  end
  
  if elements.include?("function")
   function = params[:function] ? params[:function] : "Callback"
   page.call(function, params)
  end
  
  }
 end

这个方法中对于render(:update)以及后面的page都不明白是什么,希望作者看到能解释下 谢谢

TOP

render(:update)以及后面的方法都是Ajax相关的辅助函数。

page代表当前的HTML页面,replace_html,代表将id为items的元素的innerHTML设置为 从模板"items/items"渲染而来的内容。

page.call 是调用Javascript的函数 function。

建议买本Agile web development with rails 第二版看看,上面有不少的相关内容。在第一版的时候没有介绍到这部分内容。
本帖最近评分记录
  • beckcmmin R币 +3 饿...受益非浅 2007-11-1 20:16
谢谢大家加入Ruby中文社区!
[寻找您身边的Rubyist.]

TOP

2008-11-22 18:05 Crawled by CCBot/1.0 (+http://www.commoncrawl.org/bot.html) @38.103.63.61