草庐IT

apply_matched_coupons

全部标签

javascript - 使用 .match 和 .search 的区别

我为coderbyte使用了以下代码:functionVowelCount(str){//codegoesherereturnstr.match(/[aeiou]/gi).length;}//keepthisfunctioncallhere//toseehowtoenterargumentsinJavaScriptscrolldownprint(VowelCount(readline()));我理解大部分代码,除了以下部分:正斜杠和方括号的作用是什么?gi有什么作用?search()和match()有什么区别?我应该在什么情况下使用什么? 最佳答案

javascript - AngularJS 和 i18n : apply ng-repeat filters after translating list items properties

JSFiddle:http://jsfiddle.net/X2fsw/2/我尝试使用angular-translate创建多语言AngularJS应用程序.我的代码中嵌入了一个静态项目列表。此列表的每个项目都有一个标题,该标题必须以当前选择的语言显示。翻译是在翻译服务的帮助下直接在View中完成的。示例:{{myObject.title|翻译}}。我希望使用ng-repeat显示列表,然后按项目标题过滤它。但是,过滤器应用于翻译键,而不是翻译后的字符串。在保持运行时切换语言的能力的同时更正此行为的最佳方法是什么?我可以在每次语言更改时将翻译后的字符串存储为另一个属性(例如myObjec

javascript - 为什么这里的 apply() 只接受一个参数而不是两个?

我正在阅读Javascript:好的部分这本书。我对以下代码感到困惑。Function.method('curry',function(){varslice=Array.prototype.slice,args=slice.apply(arguments),that=this;returnfunction(){returnthat.apply(null,args.concat(slice.apply(arguments)));};});slice.apply(arguments)中的null在哪里? 最佳答案 arguments作为

javascript - this.initialize(arguments) 与 this.initialize.apply(this, arguments) : what's the difference?

如果您查看Backbone.js的源代码,您会看到此模式的多种用途:this.initialize.apply(this,arguments);例如,这里:varRouter=Backbone.Router=function(options){options||(options={});if(options.routes)this.routes=options.routes;this._bindRoutes();this.initialize.apply(this,arguments);};为什么不直接写this.initialize(arguments)呢?

JavaScript(正则表达式): excluding matches from output

我有这个文本:nisinontext600elit其中600是动态添加的。我怎样才能得到它?varstr=('nisinontext600elit').match(/text\d+/);alert(str);这会提醒text600,我如何才能只提醒600而无需额外替换单词text(如果可能的话)?感谢任何帮助,谢谢! 最佳答案 varstr=('nisinontext600elit').match(/text(\d+)/);alert(str[1]); 关于JavaScript(正则表达

javascript - 未捕获的类型错误 : Object [object Object] has no method 'apply'

我在创建的新网站上收到此UncaughtTypeError,但我无法找出导致该错误的原因。我在下面的链接中重现了这个问题,如果您查看浏览器的JS控制台,您会看到发生了错误,但没有其他任何反应。http://jsfiddle.net/EbR6D/2/代码:$('.newsitem').hover($(this).children('.text').animate({height:'34px'}),$(this).children('.text').animate({height:'0px'}));​ 最佳答案 确保将它们包装在异步回调

javascript - 单击 "Apply"按钮后应用 angularjs 过滤器

我有一个很大的数据列表(4000多个项目)。开始输入时-我的浏览器卡住(最多15秒)。所以我需要关闭自动过滤功能,并将过滤功能绑定(bind)到按钮点击。通过谷歌寻找答案没有结果。我该怎么做?请帮助我:)代码:和Controller:app.controller("smsCtrl",['$scope','smsData','createDialog','$http','$filter',function($scope,smsData,createDialog,$http,$filter){...} 最佳答案 我在帮助一位同事时遇到了

javascript - meteor js 铁路由器 : apply CSS change whenever route changes

我的应用程序中有主页、联系页面和其他几个与产品相关的页面。目标是仅将背景图像应用于特定路线:/homepage和/contact。如果用户离开任一路线,应用一些CSS更改。我现在正在和我主页上的一个助手一起破解这个,就像这样:Template.homepage.rendered=function(){varroute=Router.current();if(route.path=='/'){document.body.className="showBackgroundImage";}};这里部分获胜,因为这将激活css,但我需要在路线更改时停用。我还在我的router.js中尝试了以下

javascript - 不能将 String.prototype.match 用作 Array.some 的函数吗?

这行不通:vars='^foo';console.log(['boot','foot'].some(s.match));UncaughtTypeError:String.prototype.matchcalledonnullorundefined但是这样做:vars='^foo';console.log(['boot','foot'].some(function(i){returni.match(s)}));这是为什么?我以某种方式想象String.prototype.match函数太“原始”之类的,但究竟是为什么呢?因为我没有使用ES2015,所以第二个版本看起来很冗长。有替代方案吗

javascript - underscore.js: _.zip.apply 示例

我想看一个使用underscore.js的_.zip.apply的例子。在underscoredocumentation写成:Ifyou'reworkingwithamatrixofnestedarrays,zip.applycantransposethematrixinasimilarfashion.但是,文档没有提供示例。 最佳答案 这是您对apply的标准用法:_.zip.apply(null,[['foo','bar'],[0,1]])这将导致以下结果:[['foo',0],['bar',1]]