简体   繁体   English

在haml中将Javascript变量与datamapper一起使用

[英]Use Javascript variable in haml with datamapper

I'm having a little issue here, we are bussy with our internship and are still learning so sorry in advance for some "stupid" questions. 我在这里有一个小问题,我们忙于实习,仍在学习,因此对一些“愚蠢”的问题事先感到抱歉。

We have a Haml file where we make use of datamapper for our Database. 我们有一个Haml文件,在其中我们为数据库使用了datamapper。 For static views based on our data, we make use of datamapper-code lines in haml. 对于基于我们的数据的静态视图,我们使用haml中的datamapper代码行。

But now I wanted to use a Javascript variable, who's located in the pageload function, to use this as a parameter with our datamapper code lines in haml. 但是现在我想使用位于页面加载函数中的Javascript变量将此变量用作haml中的datamapper代码行的参数。

In our javascript: 在我们的JavaScript中:

$(document).ready(function(){
var ctrpersiteid = $.cookie('sitedata');

Part of our Haml file where we want to use our variable ctrpersiteid 我们要在其中使用变量ctrpersiteid的Haml文件的一部分

 - Interface.all(:router_id => getRouterId(ctrpersiteid)).each do |interface|
   %h3 #{interface.name}

So is there any way that I could use my Javascript variable in the haml file as parameter for our function ? 那么,有什么方法可以将haml文件中的Javascript变量用作函数的参数?

The short answer is no. 最简洁的答案是不。 Javascript is only executed in the clients browser, so there's no way to access it from your server-side haml template. Javascript仅在客户端浏览器中执行,因此无法从服务器端haml模板访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM