我想将一些 JS 脚本从控制器发送到 GSP 视图。我做了以下尝试。
控制器(购买.groovy):
def myaction={
flash.script= 'jQuery("div#header").show(1000);'
redirect(action:'edit')
}
Run Code Online (Sandbox Code Playgroud)
在purchase/myaction.gsp文件中,我尝试以下代码
<g:if test="${flash.script !=null}">
<g:javascript>
$(function() {
${flash.script}
})
</g:javascript>
</g:if>
<g:else>
<g:javascript>
$(function() {
alert('Welcome')
})
</g:javascript>
</g:else>
Run Code Online (Sandbox Code Playgroud)
我也尝试:jQuery.getScript('${flash.script}')
而不是'${flash.script}'
然而,GSP 页面总是呈现第二个脚本(else 语句)
如何在View GSP中获取会话映射对象?我想不要使用动作来发送模型中的会话.
我知道会话的类路径如下:
org.codehaus.groovy.grails.web.servlet.mvc.GrailsHttpSession
Run Code Online (Sandbox Code Playgroud)
但是如何在GSP视图中检索它.
如果我有 :
def all=[11,12,12,13,13,13,14,15,16,10]
Run Code Online (Sandbox Code Playgroud)
我想将此列表拆分为3个具有几乎相同大小的子列表.
def result=[[11,12,12],[13,13,13],[14,15,16,10]]
Run Code Online (Sandbox Code Playgroud)
我向List类的metaClass添加一个方法:它是percent
metod:
请参阅:https://stackoverflow.com/a/20005844/747579
所以我能做到:
def result=[all.percent(0,0.33),all.percent(0.34,0.66),all.percent(0.67,1)]
Run Code Online (Sandbox Code Playgroud)
我的问题是:有一种方法可以将列表拆分为n个子列表equisize,例如;
def result=all.equisize(n) // n is the number of sublist wanted
Run Code Online (Sandbox Code Playgroud) 我们注意到java 8使用了参考透明度 :
我测试了很多代码来检测这个RT,例如:
public class ReferentialTransparency {
public static int triple(int number) {
System.out.println(number);
try {
Thread.sleep(500);
} catch (Exception e) {
}
return number* 3;
}
public static void main(String[] args) {
List<Integer> vals=Arrays.asList(1,2,3,4,3);
System.out.println(vals.parallelStream()
.mapToInt(ReferentialTransparency::triple)
.sum());
}
}
Run Code Online (Sandbox Code Playgroud)
安慰 :
3
4
2
1
3
39
Run Code Online (Sandbox Code Playgroud)
我注意到Java 8运行三重方法,即使有一个元素出现了两次3
.
正如Istvan解释的那样,我的问题是:
如果三重引用透明,为什么编译器不会优化重复调用三元组(3)?
我正在使用Netbeans连接数据库.我想使用Java持久性从数据库中检索数据但我收到这些错误:
jun 18, 2014 9:41:44 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
jun 18, 2014 9:41:44 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.6.Final}
jun 18, 2014 9:41:44 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
jun 18, 2014 9:41:44 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at controle_entregas.controleEntregasUI.jMenuItemNovaEntregaActionPerformed(controleEntregasUI.java:199)
at controle_entregas.controleEntregasUI.access$100(controleEntregasUI.java:18)
at controle_entregas.controleEntregasUI$2.actionPerformed(controleEntregasUI.java:85)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6527)
at …
Run Code Online (Sandbox Code Playgroud) 我的网站上的 Vue 循环中有一个 Vue 组件。这是JS文件:
Vue.component('fb-question-text', {
props: ['question'],
template:
'<label>Prompt</label><input type="text" class="form-control" v-model="question.prompt"><a href="javascript:void" class="fb-remove">Remove</a>'
});
var questionList = new Vue({
el: '#questions',
data: {
questions: [
{
type: 'text',
id: 'question1',
prompt: ''
},
{
type: 'choice',
id: 'question2',
prompt: '',
choices: ['', '']
}
]
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的 HTML 文件的样子:
<ul id="questions">
<li v-for="(question, index) in questions">
<h4>Question {{ index + 1 }}</h4>
<fb-question-text v-if="question.type === 'text'" :question="question"></fb-question-text>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
如您所见,如果 question.type 是“text”类型,我将尝试呈现 fb-question-text 组件。虽然<li>
元素会在页面中呈现,但组件模板不会完全呈现。仅呈现模板内的第一个 …
我现在正在学习 AWS EKS,我想知道如何访问 etcd、kube-apiserver 和其他控制平面组件?
例如,当我们在 minikube 中运行如下命令时,我们可以发现etcd-minikube
,kube-apiserver-minikube
[vagrant@localhost ~]$ kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-6955765f44-lrt6z 1/1 Running 0 176d
kube-system coredns-6955765f44-xbtc2 1/1 Running 1 176d
kube-system etcd-minikube 1/1 Running 1 176d
kube-system kube-addon-manager-minikube 1/1 Running 1 176d
kube-system kube-apiserver-minikube 1/1 Running 1 176d
kube-system kube-controller-manager-minikube 1/1 Running 1 176d
kube-system kube-proxy-69mqp 1/1 Running 1 176d
kube-system kube-scheduler-minikube 1/1 Running 1 176d
kube-system storage-provisioner 1/1 Running 2 176d
Run Code Online (Sandbox Code Playgroud)
然后,我们可以通过以下命令访问它们:
[vagrant@localhost ~]$ …
Run Code Online (Sandbox Code Playgroud) 我想要一个涵盖整页的背景。
我添加Style
到body
标签。
默认情况下,背景是重复的。
当我添加时background-repeat:no-repeat
,没有重复但颜色没有出现在整页上。
我们添加这些属性:
-moz-background-size: cover;
-webkit-background-size: cover;
-o-background-size: cover;
background-size: cover;
Run Code Online (Sandbox Code Playgroud)
不过,没有新意。
ES6中的Getter方法定义为METHOD并称为ATTRIBUTE(调用obj.method
而不是obj.method(..)
)
示例:
class Job {
constructor(){
this.start=new Date();
}
get age(){
return new Date()-this.start;
}
}
Run Code Online (Sandbox Code Playgroud)
然后:
var vm=new Job();
//....
vm.age // call Getter method
Run Code Online (Sandbox Code Playgroud)
我的问题是:在ES6之前有什么替代方案,如果有的话?
我对CORS服务器进行AJAX调用,我尝试使用javascript客户端读取响应时返回的cookie,但是徒劳无功.
response.header('Access-Control-Allow-Origin', '*');
response.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept, Set-Cookie');
response.header('Access-Control-Expose-Headers', "Set-Cookie");
//------SET COOKIES
response.cookie('SessionId', GeneratorId(64), {
maxAge:3600000,
httpOnly:flase // i disable httpOnly ==> does not work
});
Run Code Online (Sandbox Code Playgroud)
var xhttp=new XMLHttpRequest();
xhttp.open("POST", "http://localhost:9090/api/map", true);
xhttp,send(`{layer:1}`);
Run Code Online (Sandbox Code Playgroud)
//Append another response' header
response.header('Access-Control-Allow-Credentials','true');
Run Code Online (Sandbox Code Playgroud)
// Before xhttp.send , I add another instruction :
xhttp.withCredentials=true;
Run Code Online (Sandbox Code Playgroud)
//Avoid the wildcard on Access-Control-Allow-Origin =>Replace the first header by :
response.header('Access-Control-Allow-Origin', request.get('Origin'));
Run Code Online (Sandbox Code Playgroud)
javascript ×4
grails ×2
java-8 ×2
amazon-eks ×1
cookies ×1
cors ×1
credentials ×1
css ×1
ecmascript-6 ×1
es5-shim ×1
getter ×1
groovy ×1
hibernate ×1
httpresponse ×1
java ×1
jpa ×1
kubernetes ×1
list ×1
persistence ×1
rendering ×1
vue.js ×1