打印

[一般问题] 新建一个条目时让它自动被选

新建一个条目时让它自动被选

制做一个目录,里面有很多条目,选择一个条目就可以添加这个条目的具体内容,我先添加一个条目的内容,然后新建一个条目,这时再添加却把内容加到原来的条目中,所以应该在我新建条目时自动选择新建的条目,使原来的条目不被选,这样才能将内容加到新建的条目中,如何实现这一功能呢?
本帖最近评分记录
  • drive2me R币 +2 Good question! 2007-9-19 11:36

TOP

你指的是dropdownlist?
谢谢大家加入Ruby中文社区!
[寻找您身边的Rubyist.]

TOP

不是,就是单纯的a链接,用鼠标一点就选上了

TOP

解决方法是:在新建一个条目时,在display方法中添加一个元素和其参数,这个元素是用来调用js方法的,参数就是具体的js方法名,整个display的参数作为一个object,这样在js中就可以引用display的所有参数了,因为在display中我们需要传一个参数,其值是新建条目的id,这样我们就可以在js方法中把当前被选条目的id改为我们新建的条目的id .不知道大家能不能看懂,看不懂可以问我啊,发站内消息或直接回复都行

TOP

重要的代码:

controller:创建新条目的action:
def create
  @Item = Item.new(params[:item])
  if @item.save  
  display(['items','function'], {:id => @item[:id] ,:function=>"change_sel"}) #整个{}中的参数作为一个object
  else
  ....................
  end
end
js文件:
var SelectedItem=0 #SelectedItem是全局变量
function change_sel(object)
{
    SelectedItem=object.id;
}
本帖最近评分记录
  • drive2me R币 +5 原创内容 2007-9-19 11:36

TOP

不好意思,看了你的代码才明白你的问题-_-!

I.forget('you'){|something| something.remember.deepen}

TOP

没记得rails里有这么个display方法啊
你自己写的吧
贴出来看看

I.forget('you'){|something| something.remember.deepen}

TOP

引用:
原帖由 insight777 于 2007-9-19 09:57 发表
重要的代码:

controller:创建新条目的action:
def create
  @Item = Item.new(params[:item])
  if @item.save  
  display(['items','function'], {:id => @item[:id] ,:function=>"chan ...
Yes, Insight777, if your code does not need to keep silence, please paste it on here and share it with us.
Program can show us everyting...we are learning from you about the problem.

Thanks.
Flying Piggy...! 
天地人合一!

TOP

不好意思,忘了这个方法了 
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

TOP

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