草庐IT

each_with_index

全部标签

javascript - D3 : use nest function to turn flat data with parent key into a hierarchy

我确信有一种非常简单优雅的方法可以做到这一点,但我不太明白。我有一些看起来像这样的输入数据:[{id:1,name:"Peter"},{id:2,name:"Paul",manager:1},{id:3,name:"Mary",manager:1},{id:4,name:"John",manager:2},{id:5,name:"Jane",manager:2}]如果可能,我想使用d3.js嵌套运算符来获取要在层次结构布局中使用的结构。像这样:[{name:"Peter",children:[{name:"Paul",children:[{name:"John"},{name:"Jan

javascript - 在 $.each 函数中使用条件来创建数组

我想遍历数组的元素,如果条件为真,我想创建一个新数组。示例:我有一个名为Messages的数组,其元素是对象,我想检查id属性是否等于5。如果是,则创建一个仅包含该对象的新数组。messages=[{"id":10,"body":"hello!"},{"id":21,"body":"hola!"},{"id":5,"body":"ciao!"}];varmessage5=[];vardataObj={};$.each(messages,function(index,value){if(value.id==5){dataObj[index]=value;}});message5.push

javascript - AngularJS fn is not a function error using $timeout with a function with parameters 错误

我正在制作一个您可以编辑文本的网页,在您停止输入1秒后,它会自动保存您输入的内容。目前我正在研究$timeout的细节。当我调用没有参数的update方法时,它可以正常工作,但是当我使用参数调用它时,我得到错误:Error:fnisnotafunction$TimeoutProvider/this.$get为什么我在执行以下操作时会收到此错误:timeout=$timeout(update(element,content),1000);但不是当我这样做的时候:timeout=$timeout(update,1000);显然我需要将参数传递给更新方法,因为我需要知道要更新什么。debou

javascript - 避免 React 中的内联函数 : How to bind functions with arguments?

我正在尝试关注no-bindReact使用他们推荐的ES6类模式的规则:classFooextendsReact.Component{constructor(){super();this._onClick=this._onClick.bind(this);}render(){return(Hello!);}_onClick(){//Dowhateveryoulike,referencing"this"asappropriate}}但是,当我需要将参数传递给_onClick时,需要更改什么?我试过类似的方法:import{someFunc}from'some/path';classFoo

javascript - 使用 async 和 await with export const

我无法完成这项工作...它说:await是一个保留字。是的,当然是……而且我想使用它:)怎么了?exportconstloginWithToken=async()=>{returndispatch=>{dispatch({type:SESSION_LOGIN_IN_PROGRESS,payload:true})letstoredData=awaitReadFromLocalDB('user')console.log(storedData)if(!storedData){invalidToken(null,dispatch)}else{storedData=JSON.parse(stor

javascript - 在 Meteor 中使用#each,检查集合中的 'last' 元素是否到达

我正在使用{{#each}}遍历Meteor中的一个集合,我想知道我是否在最后一个元素中,就像我在AngularJS中使用带有$last的ngRepeat时所做的那样。它可以用来构建人类可读的枚举,比如“我喜欢猫、狗和海豚”:Template.myTemplate.helpers({likedAnimals:function(){return['dogs','cats','dolphins'];}});Ilike{{#eachlikedAnimals}}{{#if!$first&&!$last}},{{/if}}{{#if$last}}and{{/if}}{{this}}{{/each

javascript - JS map v3 : custom marker with user profile picture

自2天以来,我一直在为一些我认为很简单的事情而苦苦挣扎,在map上,我必须为每个用户显示一个标记,其中包含用户FB个人资料图片。我想知道如何才能得到与此类似的结果?我尝试的东西真的很骇人听闻。我把FB图片作为markericon我在标记的标签上放置了一个CSS类我找小弟加这个边框和这个箭头来装饰用户头像但本地图上有多个标记时,它不起作用。.marker-labels{display:none!important;+div{background-color:$dark-gray;border:2pxsolid$dark-gray;@includeradius(0.2em);height:

javascript - Async/Await with Request-Promise 返回 Undefined

我有两个文件;server.js和scrape.js,下面是它们当前的代码片段。服务器.js:constscrape=require("./scrape");asyncfunctionstart(){constresponse=awaitscrape.start();console.log(response);}start();和scrape.js:constcheerio=require("cheerio");constrequest=require("request-promise");go=async()=>{constoptions={uri:"http://www.somew

javascript - JQuery 用 find() 反转 each()

我知道以前有人问过这种问题,但是一般的解决方法$($("input").get().reverse()).each(function(){/*...*/});对我不起作用。我有一个xml文档,其中包含我想在网页上显示的音乐会列表。所以,在JQuery中:$.ajax({type:"GET",url:"concerts.xml",dataType:"xml",cache:false,success:function(xml){$(xml).find('concert').each(function(){/*dostuff*/});}});但是,我想以相反的顺序显示音乐会。所以,我尝试了以

javascript - 使用 jQuery.each() 遍历两个数组?

如何通过一次调用jQuery.each()来迭代两个数组?这样的事情显然行不通:$.each(arr1,arr2,function(i,v){//dosomething...});那么如何做到这一点呢? 最佳答案 .concat的替代方法是双$.each:$.each([arr1,arr2],function(){$.each(this,function(i,v){//dosomething});});如果数组包含很多项目,这可能会更快。 关于javascript-使用jQuery.ea