是否可以收听所有javascript事件?
我试图猜测在AJAX请求修改DOM之后是否触发了事件.
我有一个数组String
:
String[] myArray = {"A", "B", "B", "C"};
Run Code Online (Sandbox Code Playgroud)
有没有快速计算该数组中字符串出现次数的方法?是的,我知道我可以迭代并自己做计数:
int count = 0;
String whatToFind = "B";
for (String s : myArray) {
if (s.equals(whatToFind)) {
++count;
}
}
Run Code Online (Sandbox Code Playgroud)
但我想知道是否有一个实用功能.我找不到任何东西Arrays
或ArrayUtils
.是否可以使用单线程进行此操作?
似乎我interval
永远不会被触发.
我有一个包含a的指令,$interval
我想测试它.我删除了所有与指令相关的代码,并将其添加到其控制器中:
window.called = 0;
window.interval = $interval(function () {
window.called++;
console.log('interval ' + window.called); // 4
}, 10);
console.log('initialized'); // 1
Run Code Online (Sandbox Code Playgroud)
测试看起来像这样:
describe('myDirective', function () {
beforeEach(module('myModule'));
beforeEach(function($compile, $rootScope) {
/* ... compile element in its own scope ... */
});
it('should run the interval', function () {
console.log(window.interval); // 2
waitsFor(function () {
console.log('tick'); // 3
return false;
}, 1000);
});
});
Run Code Online (Sandbox Code Playgroud)
这是一个愚蠢的考验.waitsFor
出于调试目的,该方法实际上始终返回false.但这是我在控制台中看到的全部内容:
initialized // 1
Object: {then: ..} // 2
tick …
Run Code Online (Sandbox Code Playgroud) 在从Protractor运行页面时,如何使用Chrome开发人员工具检查我的页面?当我尝试打开devtools时,我从量角器得到这个错误:
UnknownError: disconnected: not connected to DevTools
(Session info: chrome=35.0.1916.114)
(Driver info: chromedriver=2.10.267518,platform=Linux 3.5.0-49-generic x86_64)
Run Code Online (Sandbox Code Playgroud) 我做了一些更改,提交了它们并将分支推送到Gerrit(git push gerrit
).现在我的更改没有出现在Gerrit中,我认为这是因为我手动推送更改而不是使用git review.当我git review
现在跑,我得到这个错误:
remote: Processing changes: refs: 1, done
To ssh://user@gerrit-host:29418/Project
! [remote rejected] HEAD -> refs/publish/master (no new changes)
error: failed to push some refs to 'ssh://user@gerrit-host:29418/Project'
Run Code Online (Sandbox Code Playgroud)
我如何告诉Gerrit我的变更集需要进行审核?
我在 64 位 Ubuntu 上使用 Eclipse Kepler 64 位和 Sun JDK 1.7.0_25 64 位。当我使用 JDK 1.6 时,Eclipse 可以工作,但在升级到 JDK 1.7 后停止工作(使用webupd8.org的方法和流行的askubuntu解决方案),现在在启动时它告诉我有错误并检查configuration/xxx.log
文件。
这是它在启动时创建的每个日志文件内容的开头:
!SESSION 2013-07-08 15:38:11.495 -----------------------------------------------
eclipse.buildId=4.3.0.I20130605-2000
java.version=1.7.0_25
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Command-line arguments: -os linux -ws gtk -arch x86_64
!ENTRY org.eclipse.equinox.ds 4 0 2013-07-08 15:38:12.212
!MESSAGE [SCR] Exception while activating instance org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngineManager@b1320f9 of component org.eclipse.e4.ui.css.swt.theme
!STACK 0
java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Display
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2521)
at java.lang.Class.getDeclaredMethods(Class.java:1845)
at org.eclipse.equinox.internal.ds.model.ServiceComponent.getMethod(ServiceComponent.java:126)
at …
Run Code Online (Sandbox Code Playgroud) 编译完成后需要触发一个事件。
这是我的父控制器的样子:
myApp.directive("ParentDirective", ["$rootScope", "$compile",
function($rootScope, $compile) {
return {
link: function (scope, element) {
var onClick = function () {
if (!scope.childDir) {
scope.childDir = $compile('<div ng-controller="childCtrl"/>')(scope);
$(scope.element).append(scope.childDir);
}
$rootScope.$broadcast('event');
}
$(element).click(onClick);
}
}
}
]);
Run Code Online (Sandbox Code Playgroud)
在 childCtrl 我有一个听众:
$rootScope.$on('event', doSomething);
Run Code Online (Sandbox Code Playgroud)
问题是指令处理发生在我的控制器触发事件之后。有没有办法从编译器获得承诺或在编译发生后以任何方式触发事件?
我有一个服务器,它完全按照 SSE 客户端期望的格式发送数据,但 Chrome 在获取带有以下消息的 Content-Type 标头时立即关闭连接:EventSource's response has a MIME type ("text/plain") that is not "text/event-stream". Aborting the connection.
EventSource
即使服务器没有设置适当的text/event-stream
内容类型,是否也可以正常工作?
我刚刚安装了 Gerrit,我想推动它,但是我收到了一个关于 的错误Change-Id
,但它似乎在它抱怨的提交中。
$ git push gerrit HEAD:refs/publish/my-branch
Counting objects: 28, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (15/15), 4.46 KiB, done.
Total 15 (delta 12), reused 0 (delta 0)
remote: Resolving deltas: 100% (12/12)
remote: Processing changes: refs: 1, done
remote: ERROR: missing Change-Id in commit message footer
remote: Suggestion for commit message:
remote: Revert "Refactoring controllers"
remote:
remote: This reverts commit dd1c5c86b12461f61326fd102a11d9e3cb51142e.
remote:
remote: Change-Id: Iaacf80a9e4f56b58d0b648112c3eb2413988f00e
remote: …
Run Code Online (Sandbox Code Playgroud) Draggable可以在这里工作,但是当我将DIV拖到可放置区域时,警报功能不会被触发.我确定这是愚蠢的事,但也许有人可以阻止我把我的头撞到墙上,我做得对不对?
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
<title></title>
</head>
<body>
<script>
$(function() {
$( ".draggable" ).draggable();
$( ".droppable" ).droppable({
drop: function(event, ui) {
alert('dropped');
}
});
});
</script>
<div id=10 class="draggable">one</div>
<div id="trash" class="droppable"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)