javascript - 将变量转换为json路径

标签 javascript jquery json variables

我有一个来自 hash 的动态变化变量与 json 路径的联合。

示例:

$(function() {
    $(window).bind( 'hashchange', function() {
        var hash = window.location.hash.substring(1);
        $("#display_content").html(position.hash);
    });
    $(window).trigger( 'hashchange' );
});

如何将 hash 变量转换为 json url 的联合?


编辑:

通过联合我的意思是json url的一部分:(position.secondposition.content)所以每个部分由.分隔一个关节。

最佳答案

您可以使用位置[哈希]

因此将您的代码更改为

 $("#display_content").html(position[hash]);

关于javascript - 将变量转换为json路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20032519/

相关文章:

java - 圆角按钮不起作用

javascript - 使用 jquery regex 函数显示匹配的字符串

javascript - 无法将脚本文件加载到另一个脚本文件中

json - Angular 7 JSON.stringify "symbol JSON cannot be resolved"

php - Silverstripe:作为 JSON 的 CMS 页面?

javascript - 单击时如何突出显示一个句子?

javascript - OpenLayers 3 中的动态样式

javascript - 在循环集合中寻找最短路径

javascript - 延迟加载 Javascript 文件与放置在 </body> 之前的任何区别

javascript - Jquery按钮多次替换图像