草庐IT

groupby-apply

全部标签

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 - 未捕获的类型错误 : 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 - 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]]

javascript - Javascript "apply"函数在 window.external 扩展对象中不存在

我在IE8(也可能是任何IE版本)上使用javascript扩展(又名window.external)来公开某些功能。我正在尝试调用apply函数,该函数(根据here应该是)在window.external对象的每个JS函数中原生嵌入函数,但浏览器不断抛出异常,表明该函数不存在apply函数。例如,这段代码有效:functiononDataReceived(url,success,status,data,errorMessage){alert(onDataReceived);}functioninnerTest(){alert(arguments[0]+","+arguments[1

javascript - 为什么构造函数中需要apply()函数

functionSet(){//Thisistheconstructorthis.values={};this.n=0;this.add.apply(this,arguments);//Allargumentsarevaluestoadd}//Addeachoftheargumentstotheset.Set.prototype.add=function(){/*Codetoaddpropertiestotheobject'svaluesproperty*/returnthis;};这是“Javascript:权威指南”中用于创建“Set”类的代码的开头。我试图合理化apply()的必

javascript - lodash 中的 groupBy 计数

我有一个这样的对象数组:[{rating:1},{rating:2},{rating:3},{rating:1}]我想要这样的结果-{1:2,2:1,3:1}它将是Rating_Value:Count。我怎样才能在lodash中做到这一点?或者是否可以在没有lodash的情况下进行优化? 最佳答案 您可以使用lodash#countBy.varresult=_.countBy(data,'rating');vardata=[{rating:1},{rating:2},{rating:3},{rating:1}];varresult=