Tag: 每个

通过node.js使用async.js

Visit.js – 注意folloup.id引用0或“n”访问(如树) var visitSchema = new Schema({ code : {type: String, trim: true, required: false, default: ""}, Client : { id: {type: Schema.Types.ObjectId, ref: 'Client'}, }, attendant : [{ name : {type: String, trim: true, required: false, default: ""}, }], followup : [{ id : {type: Schema.Types.ObjectId, ref: 'Visit'} }], }); Client.js var clientSchema […]

翡翠模板如果声明

我有一个玉的模板文件,我试图运行基于每个循环内的JSON对象的条件。 我做错了什么让if语句工作? each content in result.content .panel.panel-default.result .panel-heading.clearfix a.gray(href='/content/#{content.id}') #{content.created_pretty} a.btn.btn-primary.btn-sm.view(href="/content/#{content.id}") View .status .well span.label.label-default #{content.priority} if "#{content.priority}" == "URGENT" .well span.badge ! 如果我将条件更改为 if "URGENT" == "URGENT" 代码确实运行成功。 我也试过了: if '"#{content.priority}" == "URGENT"' – if ("#{content.priority}" == "URGENT") 任何hlp将不胜感激!

如何使用after和each连接在下划线js中创build一个同步循环

嗨我想创build一个使用下划线js的同步循环。 对于每个循环迭代,我进行一些进一步的asynchronous调用。 但是,我需要等到每个迭代调用完成之后才能继续下一个迭代。 这是可能的下划线JS? 如果是的话,怎么样? 有人可以提供一个例子吗? _.( items ).each( function(item) { // make aync call and wait till done processItem(item, function callBack(data, err){ // success. ready to move to the next item. }); // need to wait till processItem is done. }); 更新我解决了这个使用async.eachSeries方法。 async.eachSeries( items, function( item, callback){ processItem(item, function callBack(data, err){ // Do the […]

asynchronous每个和foreachfunction

我试图使用asynchronous的每个函数来调用abc函数,我遇到了一些问题。 代码如下。 我在这里使用for循环的原因是因为当我尝试使用每个函数时,传递到abc函数url的url是以数组而不是string的forms。 所以我想知道是否有任何其他的方式来清除这个,而不必添加for循环。 在添加一对print语句之后,我意识到代码从不执行传递http.get(url [a],newFileLoc,function(error,result){出于某种原因,总是有一个错误消息“async.each(urls,downloadFile (url,函数(){TypeError:对象#没有方法'每个'“ 所以我想我真正的问题是,代码究竟有什么问题? 我尝试使用forEach而不是每个,但仍然有另一个错误“迭代器(x,函数(错误){TypeError:undefined不是一个函数”)。 有人请帮忙! var abc = function ( url, cb ) { for (var a = 0; a < url.length; a++){ var index = url[a].lastIndexOf("/") + 1; var filename = url[a].substr(index); var newFileLoc = "./tmp/" + filename; http.get(url[a], newFileLoc, function (error, result) { if (error) { console.error(error); } […]

翡翠列表迭代内有不同的内容

有什么办法来遍历列表,并获得每个列表项中的不同内容? 我现在拥有的是这样的: ul.tabs li.tab-header-and-content a.tab-link(href="") Strategic overview .tab-content .col-4 p Our world is changing fast. Global population is rising rapidly. There is growing pressure on resources. Rising energy prices and climate change have created a need for new lower carbon energy sources. p All of this is driving the transition towards a resource and energy […]

如何在另一个asynchronous`each`方法(NodeJS)内部进行asynchronous方法调用?

如何在另一个asynchronous方法中调用asynchronous方法(NodeJS)? 具体的例子 – 使用数据库,我需要删除所有logging。 但是我不能只删掉整个集合,我需要逐一销毁每个logging,在删除之前我需要读取logging,在应用程序中执行一些业务逻辑,然后删除它。 所以,让我们尝试实现我们的deleteAll方法(实际上它是一个来自node-mongodb-native驱动程序的真实API): deleteAll = function(selector, callback){ collection.find(selector).each(function(err, doc){ if(err){ callback(err) }else{ if(doc === null){ // each returns null when there's no more documents, we are finished. callback(null) }else{ doSomeBusinessLogicBeforeDelete(doc) // How to delete it using asynchronous `remove` method? collection.remove({_id: doc._id}, function(err){ // What to do with this callback? // And how […]

MongoDB Node.js的每个方法

我有一个数据存储在数据库中的数组。 当我查看数据是否已经存在时,即使使用limit(1),each()也会调用两次。 我不知道这里发生了什么 collection.find({ month: 'april' }).limit(1).count(function(err, result){ console.log('counter', result); }); collection.find({ month: 'april' }).limit(1).each(function(err, result){ console.log('each', result); }); collection.find({ month: 'april' }).limit(1).toArray(function(err, result){ console.log('toArray', result); }); 此时,4月份确切的1个数据集已经存储在集合中。 上面的查询会产生这样的输出: count 1 each {…} each null toArray {…} 在mongo shell中,我检查了count()和forEach()方法。 一切都按预期工作。 这是一个驱动问题吗? 我做错了什么?