简体   繁体   English

移动环境上的Object.keys()(Adobe Acrobat Reader)

[英]Object.keys() on mobile environment (Adobe Acrobat Reader)

i'm trying to iterate over some Object keys and then fill some DropDowns with the values. 我试图遍历一些对象键,然后用值填充一些DropDowns。 On the PC it's working perfectly fine with every solution i've tried - unfortunately on mobile it's not. 在PC上,我尝试过的每种解决方案都可以正常工作-不幸的是,在移动设备上则不是。

So here's what i've tried: 所以这是我尝试过的:

  • Polyfilling Object.keys Polyfilling Object.keys
  • tried this method from someone here on stackoverflow ('old version'): 在stackoverflow(“旧版本”)上从某人尝试过此方法:
 function getKeys(obj) {
    var keys = [];
    iterate(obj, function (oVal, oKey) { keys.push(oKey) });
    return keys;
  }

  function iterate(iterable, callback) {
    for (var key in iterable) {
      if (key === 'length' || key === 'prototype' || !Object.prototype.hasOwnProperty.call(iterable, key)) continue;
      callback(iterable[key], key, iterable);
    }
  }


The Object/Script: 对象/脚本:

 var obj = { "set1": { "subSet1": { "val1": "", "val2": "", "val3": "" }, "subSet2": { "val1": "", "val2": "", "val3": "" } } ... } var arr = []; Object.keys(obj["set1"]).forEach(function(key) { arr.push(obj["set1"][key][val1]); }); 

after some testing i can tell that the problem is: the for...in statement does not work on mobile. 经过一些测试,我可以说问题出在: for...in语句不适用于移动设备。

since it's impossible(?) to debug properly on mobile, there's no additional information i could give you. 由于不可能(?)在移动设备上进行正确的调试,因此我无法提供其他信息。 (error messages or sth) (错误消息或某物)

Do you guys have a simple workaround? 你们有一个简单的解决方法吗?

tl/dr: Iterate over Object keys and fill an array with the key-names without the use of the for...in statement tl / dr:遍历对象键并使用键名填充数组,而无需使用for...in语句


edit1: just to complete things.. This is working on PC but not on mobile EDIT1:刚刚完成的事情。这工作在电脑,但无法在手机上

  var testObj = {"a":"aa", "b":"bb", "c":"cc"}; for (var keys in testObj) { app.alert(keys) } for each (var keys in testObj) { // not working mobile either } 


since the DropDownLists aren't that huge and i need to get stuff done, i'll stick with manually creating the arrays i need, for now. 由于DropDownList并不是那么大,而且我需要完成工作,因此,我将暂时坚持手动创建所需的数组。 Still curious though. 仍然很好奇。

It's not possible with Adobe Reader Mobile using Acrobat JavaScript. 使用Acrobat JavaScript的Adobe Reader Mobile无法实现。 Populating comboboxes (DropDowns) and listboxes is done using the Field.setItems() method which isn't available in Reader Mobile. 使用Field.setItems()方法填充组合框(DropDowns)和列表框,该方法在Reader Mobile中不可用。

For example, on Desktop versions, the following code will populate the "StateBox" field with the values in the array. 例如,在桌面版本上,以下代码将使用数组中的值填充“ StateBox”字段。 The first item in the inner array is the user value (presented in the UI) and the second is the export value (the value exported when the data is submitted). 内部数组中的第一项是用户值(在UI中显示),第二项是导出值(提交数据时导出的值)。

var c = this.getField("StateBox");    
c.setItems([["California", "CA"],["Massachusetts", "MA"], ["Arizona", "AZ"]]);

The same code simply fails on mobile without presenting an error. 相同的代码仅在移动设备上失败而没有出现错误。

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

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