【发布时间】:2014-09-27 01:35:48
【问题描述】:
我正在处理一个页面,该页面应该有一个输入字段和一个屏幕键盘,用 js 实现。我用过这个键盘:http://jabtunes.com/notation/keyboardcanvasexamples.html
输入字段得到输入就好了,问题是依赖于这个输入字段的角度过滤器不起作用。我在这个 plunker 中发现了一个类似的问题,但没有解决方案: http://plnkr.co/edit/FnrZTAwisYub5Vukaw2l?p=preview
html:
<html ng-app="plunker">
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.min.js"></script>
<script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.6.0.js"></script>
<script src="example.js"></script>
<script src="jKeyboard.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class='container-fluid' ng-controller="TypeaheadCtrl">
<pre>Model: {{selected| json}}</pre>
<input type="text" ng-model="selected" id="testInput" typeahead="state.name for state in states | filter:$viewValue | limitTo:8">
</div>
<button id="btn">E</button>
</body>
</html>
js:
angular.module('plunker', ['ui.bootstrap']);
function TypeaheadCtrl($scope) {
$scope.selected = undefined;
$scope.WatchPrintList = function () {
$scope.selected= {};
$scope.$watch('#testInput', function(newVal, oldVal) {
$scope.selected = newVal;
}, true);
}
$scope.states = [
{"name":"Alabama","alpha-2":"AL"},
{"name":"Alaska","alpha-2":"AK"},
//etc etc
];
}
使用屏幕键盘键入时,没有过滤器响应,但使用真实键盘键入时,它们会得到更新,数据也会被相应地过滤。为什么?
感谢您的帮助!
【问题讨论】:
-
正如@user3651406 所指出的,问题在于 jKeyboard.js 不能模拟真实的键盘事件。您需要自己修改 jKeyboard,至少要触发“输入”事件。或者找到另一个更强大的库。
标签: javascript html angularjs keyboard on-screen-keyboard