当我尝试实现如下地图时,这是一个奇怪的错误.
Map<String, Integer> cache = new HashMap<String, Integer>();
Run Code Online (Sandbox Code Playgroud)
我正在使用JDK 1.7并且不确定为什么会出现此错误并通过添加强制转换更改上述行会删除错误.我在发布这个问题之前看了一下stackoverflow中的相关帖子似乎是个奇怪的问题.
Map<String, Integer> cache = (Map<String, Integer>) new HashMap();
Run Code Online (Sandbox Code Playgroud) 当我尝试解析中的日期时IE 11,它抛出NaN,但在chrome / firefox中,我得到了以下内容timestamp 1494559800000
Date.parse("?5?/?12?/?2017 09:00 AM")
Run Code Online (Sandbox Code Playgroud)
以下是在IE 11中失败的情况。是否有其他库或方法可以在IE 11中解决此问题?
tArray 包含 ["09:00 AM", "05:00 PM"];
var tArray = timings.toUpperCase().split('-');
var timeString1 = currentDate.toLocaleDateString() + " " + tArray[0];
var timeString2 = currentDate.toLocaleDateString() + " " + tArray[1];
var currentTimeString = currentDate.toLocaleDateString() + " " + currentTime.toUpperCase();
//Below is the condition which is failing.
if (Date.parse(timeString1) < Date.parse(currentTimeString)
&& Date.parse(currentTimeString) < Date.parse(timeString2)) {
Run Code Online (Sandbox Code Playgroud)
我创建了一个失败的虚拟小提琴。 https://jsfiddle.net/vwwoa32y/
为什么我得到这个错误无法读取未定义的属性?
为什么它无法阅读formName.controls['email'].touched但能够阅读formName.get('custDetails').touched
<form [formGroup]="formName">
<fieldset formGroupName="custdetails">
<div class="form-group" [ngClass]="{'has-error': formName.controls['email'].touched
&& formName.controls['email'].hasError('invalidEmailAddress')}">
<label class="control-label">Email</label>
<input type="text" class="form-control"
formControlName="email" name="email" required />
</div>
</fieldset>
</form>
Run Code Online (Sandbox Code Playgroud)
当我们使用formName.get('custdetails.email').touched...我得到下面的错误
TypeError:_this.subscribe不是新版ZoneAwarePromise(http:// localhost:3000/node_modules/zone)的eval函数(http:// localhost:3000/node_modules/rxjs/operator/toPromise.js:68:15). js/dist/zone.js:551:29)在Object.toPromise(http:// localhost:3000/node_modules/rxjs/operator/toPromise.js:66:12)_convertToPromise(http:// localhost:3000 /在FormControl.eval的Array.map(native)中的node_modules/@angular/forms//bundles/forms.umd.js:541:73)[as asyncValidator](http:// localhost:3000/node_modules/@ angular/forms //bundles/forms.umd.js:530:101)在FormControl.AbstractControl._runAsyncValidator(http:// localhost:3000/node_modules/@angular/forms//bundles/forms.umd.js:2670:62)at at FormControl.SetValue中的FormControl.AbstractControl.updateValueAndValidity(http:// localhost:3000/node_modules/@angular/forms//bundles/forms.umd.js:2630:26)(http:// localhost:3000/node_modules/@ angular/forms // bundles/forms.umd.js:2988:18)在DefaultValueAccessor.eval [as onChange](http:// localhost:3000/node_modules/@angular/forms//bundles/forms.umd.js:1658:21)在CompiledTemplate.proxyViewClass.View_ReactiveFormComponentFive0.handleEvent_36的Wrapper_DefaultValueAccessor.handleEvent(/InternalFormsSharedModule/DefaultValueAccessor/wrapper.ngfactory.js:29:34) (/AppModule/ReactiveFormComponentFive/component.ngfactory.js:717:45)在CompiledTemplate.proxyViewClass.eval(http:// localhost:3000/node_modules/@angular/core//bundles/core.umd.js:12397:41)在ZoneDelegate.invokeTask( …
从有效的Java书中可以看出," 如果一个对象是不可变的,那么它总是可以被重用 ".
String s = "shane";
String p = "shane";
Run Code Online (Sandbox Code Playgroud)
此版本使用a single String instance,而不是每次执行时都创建一个新版本.此外,保证对象将被在同一虚拟机中运行的任何其他代码重用,这些代码恰好包含相同的字符串文字.
下面的最终课程也是不可改变的呢?点对象可以重复使用吗?
public final class Point {
private final int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() { return x; }
public int getY() { return y;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以提供一个上面的例子immutable class,它的对象/实例可以重复使用吗?我只是对可重用性如何发生感到困惑?
我能够String与IntegerClasses 相关联,但不能与用户定义的类相关联.
谁能告诉我如何使用fnServerData?
$(document).ready( function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "xhr.php",
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} );
} );
Run Code Online (Sandbox Code Playgroud)
下面是我的Ajax调用,我想ajax call用fnServerData 替换它.
$.ajax({
type: 'GET',
url: url,
jsonp: true,
contentType: "application/json",
dataType: 'jsonp',
success: function (data) {
$.each(data.value, function(i,item){
table.fnAddData(item);
});
},
error: function (e) {
console.log(e.message);
}
});
Run Code Online (Sandbox Code Playgroud)
http://datatables.net/ref#fnServerData
什么是sSource,fnCallback和oSettings?谁能告诉我如何使用fnServerData?
为什么是原型property的instance投掷undefined?。
function Test(name){
this.name = name;
}
Test.prototype = {
constructor: Test,
sayHello : function(){
console.log(this.name);
}
}
var z = new Test("Hello");
console.log(z.prototype); //undefined
console.log(zUtils.constructor); // Test
Run Code Online (Sandbox Code Playgroud)
我可以通过z.sayHello()访问 sayHello 方法,那么为什么我instance prototype返回的我是 undefined 而不是Test.prototype?。
任何人都可以解释我如何hard binding在JavaScript中工作?
function foo() {
console.log(this.a);
}
var obj = {
a: 2
};
var bar = function() {
foo.call(obj);
};
bar(); // 2
setTimeout(bar, 100); //
Run Code Online (Sandbox Code Playgroud)
我对这个功能更感兴趣.
var bar = function() {
foo.call(obj);
};
Run Code Online (Sandbox Code Playgroud)
为什么我们foo.call(obj)在另一个里面function?我们可以直接使用它吗?
setTimeout(foo.call(obj), 100); // still results in 2.
Run Code Online (Sandbox Code Playgroud) 我有一个忘记密码表单,当用户输入电子邮件时,它会点击后端并向用户发送电子邮件链接,如下所示.
用户单击链接,该链接调用后端服务.我怎样才能控制这个网址angular?所以,基本上这会调用后端资源,但我希望这个url也能在前端处理.
如果这个问题不是那么清楚,任何人都可以向我展示一个在AngularJS和NodJs或任何后端忘记密码实现的例子.
当它能够w从外部范围拾取时,为什么不能拾取z?
var w = 1, z = 2;
function foo( x = w + 1, y = x + 1, z = z + 1 ) {
console.log( x, y, z );
}
foo(); Run Code Online (Sandbox Code Playgroud)
12 AM 被认为是第二天
timeone = "5/18/2017 01:00 AM"
currenTime = "5/18/2017 05:55 AM"
timetwo = "5/18/2017 12:00 AM"
Run Code Online (Sandbox Code Playgroud)
我发现时间到了这个condition失败了12:00 AM,我该如何处理这个案子呢?
timeone.isBefore(currentTime) => passes
currentTime.isBefore(timetwo) => fails
if (timeone.isBefore(currentTime) && currentTime.isBefore(timetwo)) {
}
Run Code Online (Sandbox Code Playgroud)
更新:
var timeone = moment(time1, 'MM/DD/YYYY hh:mm a');
var timetwo = moment(time2, 'MM/DD/YYYY hh:mm a');
var currentTime = moment(currentTime, 'MM/DD/YYYY hh:mm a');
Run Code Online (Sandbox Code Playgroud) javascript ×7
java ×2
oop ×2
ajax ×1
angular ×1
angularjs ×1
ecmascript-6 ×1
immutability ×1
jquery ×1
momentjs ×1
node.js ×1
typescript ×1