草庐IT

conditional-statements

全部标签

javascript - typescript 错误 : A 'super' call must be the first statement in the constructor when a class contains initialized properties

我的项目中有以下typescript错误..让我分享一下一个示例,以便您了解正在处理的内容。moduleCoreWeb{exportclassControllerimplementsIController{public$q;public$rootScope;public$scope:ng.IScope;public$state:ng.ui.IStateService;public$translate:ng.translate.ITranslateService;publicappEvents;publiccommonValidationsService;publicdefaultPag

javascript - Firestore : Multiple conditional where clauses

例如,我的图书列表有动态过滤器,我可以在其中设置特定的颜色、作者和类别。此过滤器可以一次设置多种颜色和多个类别。Book>Red,Blue>Adventure,Detective.如何有条件地添加“where”?firebase.firestore().collection("book").where("category","==",).where("color","==",).where("author","==",).orderBy("date").get().then(querySnapshot=>{... 最佳答案 如您在A

javascript - JSLint 验证错误 "combine this with the previous var statement"

JSLint验证错误“将此与前面的var语句结合起来”我如何结合使用它才不会出现JSLint验证错误?我在getClassName函数的代码行中收到验证错误。$(document).ready(function(){'usestrict';//ThisfunctionisusedtocalculatethedatefunctiondateString(dateToDisplay){varmonthNames=['January','February','March','April','May','June','July','August','September','October','

javascript - JS : Why Is This Slower? 它不应该测试其他 OR 条件但它确实如此?

我刚刚测试了一些东西。我一直认为在OR条件下,一旦计算机/浏览器发现某些东西是真的,它就会返回它并且不会测试其他条件。我围绕这个假设构建了我的代码。但是,我对它进行了计时,看起来长测试花费了x4倍,对此有什么解释吗?注意:已在GoogleChrome控制台中测试。JSPerf:http://jsperf.com/or-condition返回真||1http://jsperf.com/or-condition2var条件=真||1;返回条件;http://jsperf.com/or-condition3if(true||1)returntrue好像比较快编辑:我刚刚发现true之后的条件

javascript - Extjs 同步商店给我一个 url is undefined error under specific conditions

我有4个启用了拖放插件的网格。它们的初始网格取决于数据库中名为state_id的值。当我将所选行放入新网格时,我会更新state_id值,然后告诉它与数据库同步并更新相关项目的值。这在大多数情况下工作正常。当发生以下情况时,我收到thisURLisundefined错误用户点击从网格中拖动A行1到网格2用户将A行从网格2到网格1错误!网址未定义。此错误似乎仅在第一个添加到网格的项目最初来自同一网格时才会发生。用户点击将行A从网格1拖到网格2用户点击将行B从网格2拖到网格1用户点击将行A从网格2拖到网格1按预期工作!在我的Controller中放置事件处理程序:dropit:functi

javascript - 为什么语句 if ( !condition ) { console.log(condition) } 显示 true

这个问题在这里已经有了答案:Whatiswrongwithmydateregex?[duplicate](2个答案)关闭8年前。我想创建一个String方法,它接受一个RegExp和一个回调,然后通过RegExp拆分String,并将回调的返回插入拆分数组。简而言之,它会做这样的事情:"a1b2c".method(/\d/,function($1){return$1+1;})=>[a,2,b,3,c]如果字符串与RegExp不匹配,它应该返回一个数组,如下所示:"abcde".method(/\d/,function($1){return$1+1;})=>["abcde"]我写了这段代

javascript - 这个 eval 条件的目的是什么?

我在这里浏览源代码:http://js-dos.com/games/doom2.exe.html并注意到一些事情:if(typeofModule==='undefined'){Module=eval('(function(){try{returnModule||{}}catch(e){return{}}})()');}Module函数是用内联脚本标记定义的稍后在另一个内联标签中用var再次声明,这次它检查模块是否存在。我的问题:如果它只会尝试再次返回模块,那么用自调用函数声明模块有什么意义?不是已经被证明不存在了吗?为什么不直接将Module显式声明为{}?

javascript - 除非 vs if 在 Javascript 中使用感叹号?

下面的代码尝试打印出可被2整除的数字“是偶数”。不应该是if(test)then()而不是:if(!test)then(),当测试的条件是“n%2”时。下面的代码似乎是“IFnumbersareNOTdivisibleby2,printout'numberiseven'”,这似乎不符合逻辑。更一般地说,在指定条件时,编写Unless函数比使用If语句有什么优势,而我们可以简单地编写if(!condition)?非常感谢任何帮助。functionunless(test,then){if(!test)then();}functionrepeat(times,body){for(vari=0

javascript - Handlebars : conditionally add attribute

我正在尝试呈现带有选项的选择元素,就像这样{{#eachcolors}}{{title}}>{{/each}}我正在使用以下Handlebars助手Handlebars.registerHelper('isSelected',function(input,color){returninput===color?'selected':'';});问题是selected属性没有显示在任何option元素上,但是当我放置一个console.log在Handlebars助手中,我确实看到一个匹配(输入===颜色===真)。知道我在这里做错了什么吗? 最佳答案

javascript - Angular ng-repeat with condition

你如何用ng-repeat做这样的事情?我将使用文档中的示例来初始化一个包含2个friend的数组,如果我只想对所有26岁及以上的friend重复一次怎么办?Ihave{{friends.length}}friends.Theyare:[{{$index+1}}]{{friend.name}}whois{{friend.age}}yearsold. 最佳答案 创建自定义过滤器。HTML:和JS:varsomeApp=angular.module('someApp',[]);someApp.filter('age',function(