将javascript变量放入播放功能 [英] Putting javascript variable into play function

查看:72
本文介绍了将javascript变量放入播放功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的公共文件,我通常使用:

For my public files, I usually use:

@routes.Assets.at("data/table.txt")

以常规html

但是,我有一个带有变量链接的javascript

However, I have a javascript with the variable link

var file = "table.txt"//This changes depending on the code
var link = "data/"+ file;

并希望运行这样的jquery函数

And would like to run some jquery function like this

$('#mydiv').CSVToTable(@routes.Assets.at(link))

但这不起作用. 我的问题

But this does not work. My questions

  1. 为什么游戏使用@ routes.Assets.at?它在某种程度上更安全​​吗?它似乎只是将资产"放在传递给它的任何内容之前.仅使用文本"/assets/data/table.txt"有什么缺点
  2. 如何将javascript变量传递给@ routes.Assets.at

感谢进阶!

推荐答案

  1. 当您使用资产的路线时,您可以进行切换,即……舒适得多(谁来过?). CDN之间的速度要快得多.如果将硬编码URL放在各处,则在更改应用程序的位置时需要修复所有URL.
  2. 常见的JavaScript也有一些可能,例如,您可以将write路由的值传递给JS'someSpecificRoute = '@routes.Assets.at(link)';,然后在脚本中使用它

  1. It's much more... comfortable (who'd guest? :)) just when you are using assets' routes you are able to switch ie. between CDN's much faster. If you'll put hardcoded URL's everywhere you'll need to fix all of them when you'll change your app's location.
  2. There are some possibilities also with common JavaScript, you can for an example write the route's value to JS' someSpecificRoute = '@routes.Assets.at(link)'; and than use it in your script

$('#mydiv').CSVToTable(someSpecificRoute);

也许您也可以使用

maybe you can also use javascriptRoutes however you'll need to decide yourself. In general using it is good idea when you are planning to use them more than once or twice.

最后,您可以仅使用硬编码路径和通用JavaScript技术来发送其他参数.在这种情况下,出于安全原因,我只能建议您最好验证传递的参数是否适合允许的类型和/或范围.

Finally you can just use a hardcoded path and common JavaScript techniques for sending additional params. In such case I can only advice that for the security reasons it will the best if you'll validate if passed arguments fits allowed type and/or range.

这篇关于将javascript变量放入播放功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆