为什么我的三元if语句不能评估为NULL?

时间:2018-05-05 10:26:25

标签: javascript jquery html ternary-operator

我正在尝试根据数据库通过2018-05-05 16:50:58.788 INFO 6552 --- [ main] xIntegrationRequestMappingHandlerMapping : Mapped "{[/message/{id}],methods=[POST]}" onto public abstract reactor.core.publisher.Mono<java.lang.Void> org.springframework.web.server.WebHandler.handle(org.springframework.web.server.ServerWebExchange) 2018-05-05 16:50:58.789 INFO 6552 --- [ main] xIntegrationRequestMappingHandlerMapping : Mapped "{[/events],methods=[GET || POST],produces=[text/event-stream]}" onto public abstract reactor.core.publisher.Mono<java.lang.Void> org.springframework.web.server.WebHandler.handle(org.springframework.web.server.ServerWebExchange) 2018-05-05 16:50:59.191 INFO 6552 --- [ctor-http-nio-1] r.ipc.netty.tcp.BlockingNettyContext : Started HttpServer on /0:0:0:0:0:0:0:0:8080 2018-05-05 16:50:59.192 INFO 6552 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8080 2018-05-05 16:50:59.196 INFO 6552 --- [ main] d.e.sample.webflux.WebfluxApplication : Started WebfluxApplication in 2.608 seconds (JVM running for 3.419) 2018-05-05 16:51:06.918 DEBUG 6552 --- [ctor-http-nio-2] o.s.web.reactive.DispatcherHandler : Processing POST request for [http://localhost:8080/message/4] 2018-05-05 16:51:06.932 DEBUG 6552 --- [ctor-http-nio-2] s.w.r.r.m.a.RequestMappingHandlerMapping : Looking up handler method for path /message/4 2018-05-05 16:51:06.933 DEBUG 6552 --- [ctor-http-nio-2] s.w.r.r.m.a.RequestMappingHandlerMapping : Did not find handler method for [/message/4] 2018-05-05 16:51:06.967 TRACE 6552 --- [ctor-http-nio-2] o.s.w.r.r.method.InvocableHandlerMethod : Invoking 'org.springframework.integration.webflux.inbound.WebFluxInboundEndpoint.handle' with arguments [org.springframework.web.server.adapter.DefaultServerWebExchange@775cdb20] 2018-05-05 16:51:06.967 TRACE 6552 --- [ctor-http-nio-2] o.s.w.r.r.method.InvocableHandlerMethod : Method [org.springframework.integration.webflux.inbound.WebFluxInboundEndpoint.handle] returned [MonoDefer] 2018-05-05 16:51:06.967 DEBUG 6552 --- [ctor-http-nio-2] o.s.w.r.r.method.InvocableHandlerMethod : Response fully handled in controller method 2018-05-05 16:51:11.363 DEBUG 6552 --- [ctor-http-nio-3] o.s.web.reactive.DispatcherHandler : Processing POST request for [http://localhost:8080/message/4] 2018-05-05 16:51:11.363 DEBUG 6552 --- [ctor-http-nio-3] s.w.r.r.m.a.RequestMappingHandlerMapping : Looking up handler method for path /message/4 2018-05-05 16:51:11.363 DEBUG 6552 --- [ctor-http-nio-3] s.w.r.r.m.a.RequestMappingHandlerMapping : Did not find handler method for [/message/4] 2018-05-05 16:51:11.364 TRACE 6552 --- [ctor-http-nio-3] o.s.w.r.r.method.InvocableHandlerMethod : Invoking 'org.springframework.integration.webflux.inbound.WebFluxInboundEndpoint.handle' with arguments [org.springframework.web.server.adapter.DefaultServerWebExchange@71f648a3] 2018-05-05 16:51:11.364 TRACE 6552 --- [ctor-http-nio-3] o.s.w.r.r.method.InvocableHandlerMethod : Method [org.springframework.integration.webflux.inbound.WebFluxInboundEndpoint.handle] returned [MonoDefer] 2018-05-05 16:51:11.364 DEBUG 6552 --- [ctor-http-nio-3] o.s.w.r.r.method.InvocableHandlerMethod : Response fully handled in controller method 函数返回的值来更改附加按钮的文本。

document.InsertList( numberedList, .Font(new Xceed.Words.NET.Font("Cambria"), 15 );

  numberedList.Items[2].Font(new Xceed.Words.NET.Font("Cambria"));

但它对NULL不起作用,即使该函数返回NULL但它不起作用我尝试了Ajax .append($('<td>').attr('id', "tdBookingStatus" + i).html(val.HasCustomerArrived === true ? "Checked in" : (val.HasCustomerArrived == null) ? " ": "Cancelled")) 以及==但没有任何作用。

1 个答案:

答案 0 :(得分:0)

如果您正在考虑该值,还需要检查=== ''。使用null无效。

//for blank value
var test = '';
var res = test === true ? "Checked in" : (test === null || test === '') ? " ": "Cancelled"

console.log(res);

//for null value
var test = null;
var res = test === true ? "Checked in" : (test === null || test === '') ? " ": "Cancelled"

console.log(res);

//for true value
var test = true;
var res = test === true ? "Checked in" : (test === null || test === '') ? " ": "Cancelled"
console.log(res);

//for false value
var test = false;
var res = test === true ? "Checked in" : (test === null || test === '') ? " ": "Cancelled"
console.log(res);