我正在尝试从javascript自动填充搜索栏元素重定向。
搜索字段除了一件事外完美无缺。 如果我在 www.example.com/foo ,请点击搜索栏中的数据。它将我重定向到这个页面: www.example.com/news/1
当我再次尝试搜索栏时。然后点击搜索栏中的产品数据。它将我重定向到 www.example.com/news/products/1
但我想 www.example.com/products/1
“/ news”必须消失。
if(window.location.pathname.split("/")[1] === "news"){
window.location.hostname.href ="?tab=" +ui.item.category_id+"&id="+ui.item.id;
}
else
window.location.href ="products?tab=" +ui.item.category_id+"&id="+ui.item.id;
window.location.hostname.href
对我不起作用?我如何使用干净的链接然后添加像“/ products / ui.item.id”
我的简介是我无法重定向(href)清洁路线。
答案 0 :(得分:1)
您可以使用document.location.origin
来获取此页面的基本网址。
window.location.href = window.document.location.origin + "products?tab=" + ui.item.category_id + "&id=" + ui.item.id;
答案 1 :(得分:0)
尝试设置sql = "select milestones.id,foo.status,milestones.name,foo.created from project_statuses inner join projects on project_statuses.project_id=projects.id inner join project_milestones on project_milestones.project_id=projects.id inner join milestones on milestones.id=project_milestones.milestone_id inner join (SELECT project_milestone_id as id,status,created_at as created FROM project_milestone_report_statuses s1 WHERE created_at = (SELECT MAX(created_at)
FROM project_milestone_report_statuses s2
WHERE s1.project_milestone_id = s2.project_milestone_id) GROUP BY project_milestone_id,status,created_at) as foo on project_milestones.id=foo.id "
ActiveRecord::Base.connection.execute(sql)
。
例如,设置window.location.pathname
会导致重定向到window.location.pathname = '/products/42'
。