我有以下3个文件,
A.java:
class A {
private float b;
public A(float b) {
this.b = b;
}
public float getB() {
return b;
}
}
Run Code Online (Sandbox Code Playgroud)
C.java:
import java.util.Arrays;
class C {
private A[] d;
private int i = 0;
public C() {
d = new A[2];
}
public float totalB() {
return Arrays.stream(d).reduce((e, f) -> e.getB() + f.getB()).get();
}
public void addB(A b) {
d[i++] = b;
}
}
Run Code Online (Sandbox Code Playgroud)
D.java:
class D {
public static void main(String[] args) {
C c …Run Code Online (Sandbox Code Playgroud) 在我的脚本顶部,我有以下内容:
// ==UserScript==
// @name Test script
// @description testing auto-update
// @namespace http://tampermonkey.net/
// @author newbie
// @version 1.0.0
// @updateURL https://github.com/mygithubaccount/test/raw/master/test.user.js
// @downloadURL https://github.com/mygithubaccount/test/raw/master/test.user.js
// @match http://awebsite.com/*
// @run-at document-end
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_getResourceURL
// @grant GM_xmlhttpRequest
// ==/UserScript==
Run Code Online (Sandbox Code Playgroud)
请注意,这些值仅作为示例。
当我对脚本进行更改并增加 github 上的版本号,然后将更改推送到 master 时,它会更新原始脚本链接,但是我没有从 Tampermonkey 获得自动更新,就像在弹出窗口中说脚本有更新一样。只有当我手动转到链接并重新安装脚本以更新它时,它才会更新。
如何使用弹出窗口进行此自动更新?
我有一个像这样的数组,例如:
const arr = ['foo', 'bar', 'baz'];
arr可以有任何长度,我只是用这个作为例子。我将如何动态地将其添加arr到 ejs 上的列表中。
我知道我可以做到这一点
// index.ejs
<!doctype html>
<html>
<body>
<ul>
<li><%= item %></li>
</ul>
</body>
</html>
// app.js
res.render('index', {
item: arr[0]
})
Run Code Online (Sandbox Code Playgroud)
这将仅渲染数组中的第一项。我将如何做到它最终会像这样:
<html>
<body>
<ul>
<li>foo</li>
<li>bar</li>
<li>baz</li>
</ul>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 目前我有一个对象,我正在循环它以获得如下输出:
var obj = {
"first": {
"Bob": {
"1": "foo",
"2": "bar"
},
"Jim": {
"1": "baz"
}
},
"second": {
"Bob": {
"1": "qux"
},
"Jim": {
"1": "quux"
},
},
}
for (let position in obj) {
console.log(`In ${position} position`);
let pos = obj[position];
for (let name in pos) {
person = pos[name];
for (let item in person) {
let thing = person[item];
console.log(`${position} ${name} ${item} ${thing}`)
}
}
}Run Code Online (Sandbox Code Playgroud)
但是,我觉得这可能是一种混乱的方式,因为我嵌套了多个for循环,是否有更简洁的方法来做到这一点?也许使用ES6/ES7 + /等.?
javascript ×2
object ×2
ejs ×1
java ×1
java-8 ×1
node.js ×1
oop ×1
tampermonkey ×1
userscripts ×1