背景选项卡上的页面未正确加载(Page on background tab not loading properly)
我正在使用带有jQuery的Polymer 1.0,并创建了一个小的单页应用程序。 但是,当我“在新选项卡中打开链接”时,页面不会加载。 更具体地说,它以模板形式加载并触发ajax请求以获取数据,但不会将任何数据填充到模板中。 例如,简化版本:
$(document).ready(function(){ url = '/ajax/get_data'; $.post(url, '', function(data) { if (data.data.id !== undefined & data.data.id > 0) { $('.gt-info-location').text(data.data.name); $('.gt-city-population').text(data.population); $('.gt-city-timezone').text(data.data.timezone); $('.gt-city-county').text(data.data.county); $('google-map')[0].latitude = data.data.latitude; $('google-map')[0].longitude = data.data.longitude; $('#location-frontpage').css('background',"url('pictures/"+data.data.image_file+"') center / cover"); $('#location-back').css('background',"url('pictures/"+data.data.image_file+"') center / cover"); } }); });
我知道
$.post
正在发生并从Web请求日志返回正确的数据,但是.text()
或.css()
函数都没有对页面进行任何更改。 并且,是的,在打开的选项卡中加载相同的页面工作正常。I am using Polymer 1.0 with jQuery and have created a small single page app. When I "Open link in new tab", however, the page doesn't load. More specifically, it loads in template form and fires the ajax requests to get the data, but none of that data gets populated into the template. For example, a simplified version:
$(document).ready(function(){ url = '/ajax/get_data'; $.post(url, '', function(data) { if (data.data.id !== undefined & data.data.id > 0) { $('.gt-info-location').text(data.data.name); $('.gt-city-population').text(data.population); $('.gt-city-timezone').text(data.data.timezone); $('.gt-city-county').text(data.data.county); $('google-map')[0].latitude = data.data.latitude; $('google-map')[0].longitude = data.data.longitude; $('#location-frontpage').css('background',"url('pictures/"+data.data.image_file+"') center / cover"); $('#location-back').css('background',"url('pictures/"+data.data.image_file+"') center / cover"); } }); });
I know the
$.post
is happening and returning the correct data from the web request log, but none of the.text()
or.css()
functions are making any changes to the page. And, yes, loading the same page in an open tab works fine.
原文:https://stackoverflow.com/questions/36289923
最满意答案
这是一行:
return DataCenterEnum.values()[new Random().nextInt(3) + 1)];
对于那些需要更严格控制代码的人来说,这是一个更安全的版本,它不依赖于枚举实例的顺序:
return new DataCenterEnum[]{DC1, DC2, DC3}[new Random().nextInt(3)];
Here's the one line:
return DataCenterEnum.values()[new Random().nextInt(3) + 1)];
For those who require tighter control on their code, here's a safer version, which does not depend on the order of the enum instances:
return new DataCenterEnum[]{DC1, DC2, DC3}[new Random().nextInt(3)];
相关问答
更多-
Python中的随机字符串(Random strings in Python)[2023-07-11]
从(例如)小写字符生成字符串: import random, string def randomword(length): letters = string.ascii_lowercase return ''.join(random.choice(letters) for i in range(length)) 结果: >>> randomword(10) 'vxnxikmhdc' >>> randomword(10) 'ytqhdohksy' Generating strings fro ... -
phelgo , NSBarcelona的一名成员告诉我这件事,并且完美无缺! enum Localizations { static let StringId1 = NSLocalizedString("string_to_translate_1", comment: "") } let myString = Localizations.StringId1 有一个没有案例的enum可能看起来不熟悉,但是我们可以保持其所有的安全性(和代码完成),同时仍然防止Localizations被错误地实例 ...
-
生成唯一的随机字符串(Generate unique random strings)[2022-06-07]
我们真的不需要手动波动你的函数有多少次迭代(或递归)。 我相信在每次调用时,预期的迭代次数是按地理分布的(即首次成功之前的试验次数由地理分布控制 ),其平均值为1 / p,其中p是成功找到未使用的字符串的概率。 我相信p只是1 - n / 63 ^ 6,其中n是当前存储的字符串的数量。 因此,我认为你需要在数据库中存储300亿个字符串(~63 ^ 6/2),然后你的函数平均每次调用的次数超过2次(p = .5)。 此外,几何分布的方差为1-p / p ^ 2,因此即使在300亿个条目中,一个标准偏差也只是s ... -
从HashMap
返回随机值(Return random value from HashMap [2022-04-26]) 尝试将地图转换为像这样的列表(在Room类中): public Direction getRandomExit(){ Listdirections = new ArrayList (exits.keySet()); if (directions.size()==0){ return null; } Random rand = new Random(); ... -
这对于使用enum没有任何意义。 请记住, enum常量是单例:所有角色将共享每个技能对象的相同单个副本,因此所有角色将具有相同的技能编号。 这可能不是你想要的。 只用字段来代替字段会更有意义: public class Skills { private int vehicleSkill; private int hackingSkill; // etc. public Skills(Random r) { this.vehicleSkill = r.nex ...
-
这是一行: return DataCenterEnum.values()[new Random().nextInt(3) + 1)]; 对于那些需要更严格控制代码的人来说,这是一个更安全的版本,它不依赖于枚举实例的顺序: return new DataCenterEnum[]{DC1, DC2, DC3}[new Random().nextInt(3)]; Here's the one line: return DataCenterEnum.values()[new Random().nextInt(3 ...
-
Openoffice Calc:从字符串列表中返回随机字符串的公式?(Formula to return random string from list of strings?)[2023-10-09]
在OpenOffice Calc中, RAND函数返回0到1之间的值 - 因此您必须组合不同的公式才能从两个文本值中随机选择。 需要以下步骤: 将rand的结果舍入为整数; 基于该整数,从列表中选择。 请尝试以下公式: =CHOOSE(ROUND(RAND()+1);"MBA";"MSc") 或分成不同的行: =CHOOSE( ROUND( RAND()+1 ); "MBA"; "MSc" ) 根据您的本地化,您必须替换参数分隔符; 通过: 。 说明: C ... -
我希望以下Snipped可以帮助你。 当然,您可以使用Stream API简化它。 但这个概念应该是清楚的。 只需将此添加到您的枚举声明中即可。 public static CursorInfo getCursor(String search) { for(CursorInfo cursorValue : CursorInfo.values()) { for(String tool : cursorValue.toolTip) { if ...
-
你应该将你的roshambo字段存储为Roshambo而不是int并相应地更新你的setter和getter。 这是因为在Java Enums中无法将其转换为int 。 有关说明,请参阅下面的堆栈溢出链接: 在Java中将Int转换为枚举 字段名称应以小写字母开头 使用Roshambo.values()[choice] 摆脱1 + in 1 + rand.nextInt(3); 因为nextInt()方法在位置0中具有第一个枚举值。所以 Roshambo.values()[0] = ROCK Roshamb ...
-
随机枚举生成(Random enum generation)[2022-02-12]
您的RandomEnumSequenceGenerator版本不检查request ,因此它只响应任何请求,即使它不是它定制类型的请求。 最简单的解决方案可能是这样的: public class RandomEnumSequenceGenerator : ISpecimenBuilder where T : struct { private static Random _random = new Random(); private Array _values; publ ...