我是编程领域的新手,所以我会在我的javascript问题中给予我(如果是)简单的答案。
at System.Data.Entity.Internal.ThrowingMonitor.EnsureNotEntered()
at System.Data.Entity.Core.Objects.ObjectQuery`1.System.Data.Entity.Infrastructure.IDbAsyncEnumerable<T>.GetAsyncEnumerator()
at System.Data.Entity.Internal.Linq.InternalQuery`1.GetAsyncEnumerator()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Data.Entity.Infrastructure.IDbAsyncEnumerable<TResult>.GetAsyncEnumerator()
at System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.ForEachAsync[T](IDbAsyncEnumerable`1 source, Action`1 action, CancellationToken cancellationToken)
at System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.ToListAsync[T](IDbAsyncEnumerable`1 source, CancellationToken cancellationToken)
at System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.ToListAsync[T](IDbAsyncEnumerable`1 source)
at System.Data.Entity.QueryableExtensions.ToListAsync[TSource](IQueryable`1 source)
at xyz.desk.app.ccm.business.Service.CostsService.<GetCosts>d__7.MoveNext() in D:\Dev\ThatCrazyPluginProject\desk\app\xyz.desk.app.ccm.business\Service\CostsService.cs:line 89
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at xyz.desk.app.ccm.plugin.costplan.constructionprogress.ViewModel.ContructionProgressCostPlanViewModel.<LoadData>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at xyz.desk.app.ccm.plugin.settlementscheduleshost.ViewModel.SettlementSchedulesHostViewModel.<LoadCurrentSection>d__67.MoveNext() in D:\Dev\ThatCrazyPluginProject\desk\app\xyz.desk.app.ccm.ui\ViewModel\SettlementSchedulesHostViewModel.cs:line 307
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at xyz.desk.app.ccm.plugin.settlementscheduleshost.ViewModel.SettlementSchedulesHostViewModel.<LoadData>d__65.MoveNext() in D:\Dev\ThatCrazyPluginProject\desk\app\xyz.desk.app.ccm.ui\ViewModel\SettlementSchedulesHostViewModel.cs:line 282
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at xyz.desk.app.ccm.ui.ViewModel.ProjectViewModel.<LoadCurrentSection>d__115.MoveNext() in D:\Dev\ThatCrazyPluginProject\desk\app\xyz.desk.app.ccm.ui\ViewModel\ProjectViewModel.cs:line 763
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at xyz.desk.app.ccm.ui.ViewModel.ProjectViewModel.<<get_PluginsCv>b__21_0>d.MoveNext() in D:\Dev\ThatCrazyPluginProject\desk\app\xyz.desk.app.ccm.ui\ViewModel\ProjectViewModel.cs:line 120
有人可以一步一步地解释这些场景背后会发生什么?因为我无法理解为什么el会分配给我...
提前谢谢
答案 0 :(得分:0)
这是非常基本的,只是尝试使用console.log来查看传递的实际值我已经提供了一些注释来帮助。
var years = [1990, 1965, 1937, 2005, 1998];
function arrayCalc(arr, fn) {//fn is function which will execute with current array element as argument
var arrRes = [];
for (var i = 0; i < arr.length; i++) {
arrRes.push(fn(arr[i])); //fn:calculateAge(arr[i])
}
return arrRes;
}
function calculateAge(el) {//el is argument
return 2018 - el;//substract the argument from 2018
}
var ages = arrayCalc(years, calculateAge);//passing calculateAge function as argument as function pointer
console.log(ages);
答案 1 :(得分:0)
for循环中的i用于引用数组中的索引:arr[0] = 1990, arr[1] = 1965, arr[2] = 1937 etc.
在这种情况下,for循环
for (var i = 0; i < arr.length; i++) {
arrRes.push(fn(arr[i]));
}
在数组中的每个元素上调用传递的函数fn(对于calculateAge():var ages = arrayCalc(years, calculateAge);
)。该函数在将元素作为参数传入后使用el来引用该元素。
答案 2 :(得分:0)
设置数组非常基本
//setting a array
var years = [1990, 1965, 1937, 2005, 1998];
//creating a function
function calculateAge(el) {
return 2018 - el; // this will subtract every el with 2018
}
//calling a function, pass year variable & calculateAge function as argument of arrayCalc function and store its result on ages variable
var ages = arrayCalc(years, calculateAge);
console.log(ages); // show the result on console
如果我告诉你arrayCalc(arr, fn)
,这就是幕后发生的事情
for
循环处理years
数组的每个元素并调用calculateAge()
方法,在通过 2018 减去它后得到结果,并将结果推送到{每次{1}}数组,最后返回arrRes
并将其分配给arrRes
变量。
ages
输出: var arrRes = []
var result1 = 2018-1990;
arrRes = [result1];
var result2 = 2018-1965;
arrRes = [result1,result2];
var result3 = 2018-1937;
arrRes = [result1,result2,result3];
var result4 = 2018-2005;
arrRes = [result1,result2,result3,result4];
var result5 = 2018-1998;
arrRes = [result1,result2,result3,result4,result5];