草庐IT

promised-mongo

全部标签

javascript - jQuery Promise 然后在 AJAX 之后不工作

我的Promise是这样定义的:myFunc=function(){$.getJSON("./rest/api/some/url",function(json,textStatus){console.log("AJAXcallhit!");});};$.when(myFunc()).then(function(){console.log("Thenblockhit!");});在控制台中输出为:Thenblockhit!AJAXcallhit!我需要AJAX调用hit!,然后是Thenblockhit!。知道为什么会这样吗?我什至尝试实现自定义回调函数(我在Stackoverflow上

javascript - '错误 : Uncaught (in promise): No provider for Jsonp' (HTML/Javascript/Typescript/Angular2)

错误截图:.ts文件代码(SearchDisplay.component.ts):import{Component,OnInit}from'angular2/core';import{Router}from'angular2/router';import{Hero}from'./hero';import{HeroService}from'./hero.service';import{RouteConfig,ROUTER_DIRECTIVES}from'angular2/router';import{HeroesComponent}from'./heroes.component';imp

javascript - writestream 完成后如何返回 promise ?

我有这样一个函数,它创建一个写入流,然后将字符串数组写入文件。我想让它在编写完成后返回一个Promise。但我不知道如何才能完成这项工作。functionwriteToFile(filePath:string,arr:string[]):Promise{constfile=fs.createWriteStream(filePath);arr.forEach(function(row){file.write(row+"\n");});file.end();file.on("finish",()=>{/*dosomethingtoreturnapromisebutIdon'tknowhow

javascript - 为什么不能将 Promise.resolve 作为函数调用?

困扰我和我同事的事情。考虑以下...const{map,compose}=require('ramda');compose(console.log,map(Math.tan))([1,2,3]);compose(console.log,map(v=>Promise.resolve(v)))([4,5,6]);compose(console.log,map(Promise.resolve))([7,8,9]);如您所料,输出1、2和3的tan以及解决3、4和5的promise。但我的问题是......为什么第三个中断?为什么Promise.resolve的行为方式与任何其他函数不同?[1

javascript - 如何在对象字面量中使用 promise

在angular-translate2.0版$translateservice不再返回实际的翻译而是一个promise。我认为这是个好主意,因为可能会进行一些异步加载。但这让我很困惑如何在我的案例中正确使用该服务,因为我在对象文字中使用了$translate服务,就像这样$scope.myDefs=[...{field:'supplier',displayName:$translate('Supplier'),cellTemplate:"..."},...{field:'supplierSize',displayName:$translate('Size'),width:100,cel

javascript - 混合使用 ES6 Promise 和 JQuery Promise

我使用过$q(Angular.js),并且经常会在.then调用中返回promise。结果是下一个.then调用将等待上一个promise完成。我现在正在使用原生es6promises来尝试“promisify”一个基于回调的库,但我无法这样做。问题是.then链中的下一个值是一个promise对象,而不是该promise的解析值。它在promise解析之前调用下一个.then值,简单地返回最后一个返回值。有没有办法等待之前的promiseresolve?例子:$.ajax({url:"//localhost:3000/api/tokens",type:"POST",data:JSON

javascript - 了解 javascript promise ;堆栈和链接

我一直在使用javascriptpromises遇到一些问题,尤其是在堆叠链方面。任何人都可以向我解释这些不同实现之间的区别(如果有的话!)?实现1varserverSidePromiseChain;serverSidePromiseChain=async().then(function(response){console.log('1',response);returnresponse;}).then(function(response){console.log('2',response);returntrue;}).then(function(response){console.l

javascript - react native 获取 : second promise hanging

ReactNative的抓取出现奇怪的问题。它之前工作正常,不确定我更改了什么但它停止工作了。login(data,success,fail){console.log('doingfblogin');fetch(host+'/api/login?credentials='+data.credentials).then((response)=>{console.log('gotloginresponse');returnresponse.json();}).then(json=>{console.log('gotloginjson');if(json.result!='fail'){su

javascript - Unhandled Promise rejection : push. on is not a function

我正在使用Ionic2。我在尝试设置推送通知时收到此Typescrpt错误。我从教程中复制了这个示例代码,所以我希望它能工作。我一定是出了什么问题。任何想法请:UnhandledPromiserejection:push.onisnotafunction;Zone:angular;Task:Promise.then;Value:TypeError:push.onisnotafunctionpush.on('registration',function(data){typescriptimport{Push}from'ionic-native';..pushNotifications()

javascript - 我如何从这个 jsFiddle 动态添加一个延迟到 promise 中?

关于thisjsFiddle,我正在尝试动态添加一个在事件触发时创建的“延迟”,因此仅当所有延迟都已解决时才调用完成回调,包括后来添加的那些:相关代码:varpromises=[deferred1,...];varp=when.all(promises).then(function(){console.log('Alldone!!');//!trigger});promises.push(deferredFromEvent);//更新:欢迎使用Q或jQuery的建议,我正在寻找一个可行的 最佳答案 将您的固定promise视为一个独