我正在开发一个cordova 混合应用程序(目前用于android)并使用InAppBrowswer-Plugin。
我想打开一个网页并使用 post 请求登录那里(因为它目前在实际的 Android 应用程序中通过 Java 完成)。
不知何故,这不起作用,我不知道为什么。这是我正在使用的代码:
var ref = cordova.InAppBrowser.open("www.thesite.dummy", "_blank", "location=yes");
var postAsString = 'var xhttp = new XMLHttpRequest();'+
'xhttp.open("POST", "'+url+'", true);'+
'xhttp.onreadystatechange = function() {if (xhttp.readyState == 4 && xhttp.status == 200) {alert("it worked")}};'+
'xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");'+
'xhttp.send("username=dummyUser&password=dummyPW")'
console.log(postAsString);
ref.executeScript({"code":postAsString});
Run Code Online (Sandbox Code Playgroud)
如您所见,我还使用 console.log 我的“postAsString”。如果我复制这个字符串并在 www.thesite.dummy 的控制台中执行它实际上可以工作,但不能在 InAppBrwoser
简单地说我的问题是:检索具有给定大小的ArrayList的随机不连续子列表的最有效方法是什么.
以下是我自己的设计,虽然有效,但对我来说似乎有点笨拙.这是我的第一个JAVA程序,所以请原谅我的代码或问题是否符合最佳实践;)
备注:
- 我的列表不包含重复项
- 我猜想如果AimSize超过原始列表大小的一半,删除项目而不是添加项目可能会更快
public ArrayList<Vokabel> subList(int AimSize) {
ArrayList<Vokabel> tempL = new ArrayList<Vokabel>();
Random r = new Random();
LinkedHashSet<Vokabel> tempS = new LinkedHashSet<Vokabel>();
tempL = originalList;
// If the size is to big just leave the list and change size
// (in the real code there is no pass-by-value problem ;)
if (!(tempL.size() > AimSize)) {
AimSize = tempL.size();
// set to avoid duplicates and get a random order
} else if (2* AimSize …Run Code Online (Sandbox Code Playgroud) 有没有办法将一个对象属性的值链接到另一个对象属性的值?
我的想法是,我有一个类似于例外的界面,所以我需要propertys.name和.value我的对象.在这种特殊情况下,名称很容易从值构造(值是数组,名称是array.toString())
我可以使用obj.value.toString()而不是值,但代码需要用来obj.name使它适用于所有情况.
我尝试了这段代码,但它没有产生我想要的结果.我怎样才能实现理想的行为?
obj = {value: array, name: this.value.toString()}
Run Code Online (Sandbox Code Playgroud) javascript ×2
arraylist ×1
cordova ×1
hyperlink ×1
inappbrowser ×1
interface ×1
java ×1
object ×1
post ×1
properties ×1
random ×1
set ×1
sublist ×1