这是我的server.js文件和api.js文件.我在sort函数中遇到错误,我打算根据它们的属性搜索js对象.事件Schema具有名称,位置,价格,评级等属性.我试着根据它们的价格对它进行排序.
server.js
var express= require('express');
var bodyParser= require('body-parser');
var morgan = require('morgan');
var config=require('./config');
var app= express();
var mongoose=require('mongoose');
//var User=require('./database/user')
mongoose.connect('mongodb://localhost:27017/db',function(err){
if(err){
console.log(err);
}
else{
console.log("connected!");
}
});
app.use(bodyParser.urlencoded({extended: true })); //if false then parse only strings
app.use(bodyParser.json());
app.use(morgan('dev'));//log all the requests to the console
var api=require('./app/routes/api')(app,express);
app.use('/api',api);
app.get('*',function(req,res){
res.sendFile(__dirname + '/public/views/index.html');
}); // * means any route
app.listen(config.port,function(err){
if(err){enter code here
console.log(err);
}
else{
console.log("The server is running");
}
});
module.exports = router;
Run Code Online (Sandbox Code Playgroud)
api.js
var User = require('../models/user'); …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置WebStorm来开发AngularJS.我按照JetBrains的说明进行操作,我正在尝试从该教程中运行测试.
describe('PhoneCat controllers', function() {
beforeEach(module('phonecatApp'));
describe('PhoneListCtrl', function(){
it('should create "phones" model with 3 phones', inject(function($controller) {
var scope = {},
ctrl = $controller('PhoneListCtrl', { $scope: scope });
expect(scope.phones.length).toBe(3);
}));
});
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
"C:\Program Files (x86)\nodejs\node.exe" "C:\Program Files (x86)\JetBrains\WebStorm 7.0.3\plugins\js-karma\js_reporter\karma-intellij\lib\intellijRunner.js" --karmaPackageDir=C:\Users\L\node_modules\karma --serverPort=9876 --urlRoot=/
Testing started at 21:02 ...
ReferenceError: module is not defined
at null.<anonymous> (C:/Users/L/WebstormProjects/AngularJS/test/unit/ControllerTests.js:4:16)
at C:/Users/L/WebstormProjects/AngularJS/test/unit/ControllerTests.js:3:1
Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud)
我的目录布局是
测试/单元/ ControllerTest.js
测试/ karma.conf.js
karma.conf.js如下
// Karma configuration …Run Code Online (Sandbox Code Playgroud) WCF测试客户端似乎没有按任何逻辑顺序放置方法.但是,订单是一致的.在每个环境中都保持不变.
这不是按字母顺序排列的.这不是班级中方法的顺序.WCF测试客户端中的顺序与WSDL中的顺序不匹配.
虽然这不是完全随意的.订单有时与班级匹配.但是,您可以更改类中的顺序,重新编译,并在将服务添加回WCF测试客户端时,它不会更改为匹配.
那么确定订单是什么?
我的应用程序是ASP.NET Core 1.0 Web API.如果我的控制器返回一个小字符串,一切正常.但是如果字符串长度超过32768,我收到以下错误消息:
--- End of stack trace previous location where exception was thrown ---
at System.Runtime.CompillerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompillerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Htpp.Frame`1.<RequestProcessAsync>d__2.MoveNext()
Request Information
RequestID:440ed7db-0002-006f-742e-a28f82000000
RequestDate:Tue, 21 Mar 2017 11:30:40 GMT
StatusMessage:Bad Request
ErrorCode:PropertyValueTooLarge
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
[HttpGet]
[Produces("plain/text")]
public async Task<IActionResult> GetData()
{
return this.Ok(this.GetResponse());
}
private string GetResponse()
{
string retVal = string.Empty;
for (int i = 0; i < 32769; i++)
{
retVal = retVal + "a";
}
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
完整的错误消息:
Microsoft.WindowsAzure.Storage.StorageException: BadRequest
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.<ExecuteAsyncInternal>d__4`1.MoveNext() …Run Code Online (Sandbox Code Playgroud) 请参阅以下代码:
public class Program
{
private static void Main()
{
var c = new MonthClass();
string[] months = (string[])c.GetMonths();
months[0] = "Thursday";
var d = c.GetMonths();
Console.WriteLine(d.First());
}
}
public class MonthClass
{
private readonly string[] _months =
{
"January", "February", "March", "April","May","June","July",
"August","September", "October", "November","December"
};
public IEnumerable<string> GetMonths() => _months;
}
Run Code Online (Sandbox Code Playgroud)
请注意,它MonthClass._months是私有且只读.但是,第二次调用GetMonths返回Thursday作为数组的第一个元素而不是January.
如何更改私有只读成员的值MonthClass以及如何防止这种情况?
在阅读答案并进行自己的研究之后.我相信以下内容将解决这个问题:
private readonly string[] _months =
{
"January", "February", "March", "April","May","June","July",
"August","September", "October", "November","December"
}; …Run Code Online (Sandbox Code Playgroud) public void Test<T>()
{
Console.WriteLine(nameof(T));
}
Test<int>();
Run Code Online (Sandbox Code Playgroud)
这个代码字面上打印T而不是int,这根本没用.我想获得一个实际泛型类型参数的名称,而不使用反射(typeof然后对Type变量进行操作等)
我读到泛型的要点是在编译时准备好在定义中使用不同类型的代码的变体.并且nameof也是一个编译时运算符.在这种情况下,它应该足以知道这里的T是一个int.除了必须从用户端执行此操作之外,必须有一些方法可以执行此操作(例如Test<int>(nameof(int)))
如果有人对这个用例很好奇,除了调试之外我还想把这个项目的类名作为键添加到字典中.这本词典中只有一种形状.
public AddShape<T>(T shape) where T : Shape
{
dict.Add(nameof(T), shape.SerializableShape);
}
Run Code Online (Sandbox Code Playgroud) 我对各种声明SendMessage感到困惑.我怎么知道哪一个是正确的?
在我的c#winforms应用程序(Windows 7)中,我使用以下内容;
public class NativeMethods
{
[DllImport("user32.dll")]
// Currently uses
public static extern int SendMessage(IntPtr hWnd, uint wMsg, int wParam, int lParam);
// Think I should probably be using
// public static extern int SendMessage(IntPtr hWnd, uint wMsg, UIntPtr wParam, IntPtr lParam);
}
Run Code Online (Sandbox Code Playgroud)
但是调用SendMessage的代码是
NativeMethods.SendMessage(this.tv.Handle, 277, 1, 0);
Run Code Online (Sandbox Code Playgroud)
我如何确定要使用的参数,以便我可以切换到另一个声明?
c# ×4
.net ×3
angularjs ×1
asp.net ×1
asp.net-core ×1
azure ×1
dllimport ×1
generics ×1
interop ×1
jasmine ×1
javascript ×1
karma-runner ×1
node.js ×1
sendmessage ×1
wcf ×1
webstorm ×1
winapi ×1