我根据this tutorial创建了我的MEAN堆栈应用。 这是我在/ client / app / thoughtsIndex /中的ideasIndex.js。你可以思考'思考'作为职位。
/*Change your class definitions to use proper case names then use the camel case converter provide by newtonsoft*/
public class WeatherClass
{
public string Name { get; set; }
public Info Main { get; set; }
public List<InfoWeather> Weather { get; set; }
}
public class Info
{
public string Temp { get; set; }
public string Pressure { get; set; }
}
public class InfoWeather
{
public string Description { get; set; }
public string Main { get; set; }
}
var jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
var weatherClass = Newtonsoft.Json.JsonConvert.DeserializeObject<WeatherClass>(json, jsonSerializerSettings);
&#39; collectedThoughtsIndex&#39;州和&#39; userThoughtsIndex&#39;国家工作正常。
问题是,当状态为“主要”时,我想在db中显示所有想法,除了当前用户的想法。如果没有当前用户,我想在db。中显示所有想法。
I asked to the tutorial author,他说试试{user:{$ ne:$ stateParams.userId}}。但这给了我这个错误。
angular.module('meanGoroApp')
.config(function ($stateProvider) {
$stateProvider
.state('main', {
url: '/',
templateUrl: 'app/thoughtsIndex/thoughtsIndex.html',
controller: 'ThoughtsIndexCtrl',
resolve: {
query: function($stateParams) {
return {
// I need help here!!
}
}
}
})
.state('collectedThoughtsIndex', {
url: '/users/:userId/collected',
templateUrl: 'app/thoughtsIndex/thoughtsIndex.html',
controller: 'ThoughtsIndexCtrl',
resolve: {
query: function($stateParams) {
return {
collectedBy: $stateParams.userId
}
}
}
})
.state('userThoughtsIndex', {
url: '/users/:userId',
templateUrl: 'app/thoughtsIndex/thoughtsIndex.html',
controller: 'ThoughtsIndexCtrl',
resolve: {
query: function($stateParams) {
return { user: $stateParams.userId };
}
}
});
});
到目前为止,我试过了
Unhandled rejection CastError: Cast to ObjectId failed for value "[object Object]" at path "user"
at MongooseError.CastError (/Volumes/Garage/GORO/mean_goro/node_modules/mongoose/lib/error/cast.js:19:11)
at ObjectId.cast (/Volumes/Garage/GORO/mean_goro/node_modules/mongoose/lib/schema/objectid.js:147:13)
at ObjectId.castForQuery (/Volumes/Garage/GORO/mean_goro/node_modules/mongoose/lib/schema/objectid.js:187:15)
at cast (/Volumes/Garage/GORO/mean_goro/node_modules/mongoose/lib/cast.js:141:34)
at Query.cast (/Volumes/Garage/GORO/mean_goro/node_modules/mongoose/lib/query.js:2570:10)
at Query.find (/Volumes/Garage/GORO/mean_goro/node_modules/mongoose/lib/query.js:1087:10)
at /Volumes/Garage/GORO/mean_goro/node_modules/mongoose/lib/query.js:2164:21
at Query.exec (/Volumes/Garage/GORO/mean_goro/node_modules/mongoose/lib/query.js:2157:10)
From previous event:
at index (/Volumes/Garage/GORO/mean_goro/server/api/thought/thought.controller.js:78:55)
at Layer.handle [as handle_request] (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/layer.js:95:5)
at next (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/layer.js:95:5)
at /Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:330:12)
at next (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:271:10)
at Function.handle (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:176:3)
at router (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:46:12)
at Layer.handle [as handle_request] (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:312:13)
at /Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:280:7
at Function.process_params (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:330:12)
at next (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:271:10)
at Layer.handle [as handle_request] (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/layer.js:91:12)
at trim_prefix (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:312:13)
at /Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:280:7
at Function.process_params (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:330:12)
at next (/Volumes/Garage/GORO/mean_goro/node_modules/express/lib/router/index.js:271:10)
但这些都没有奏效。 请帮帮我..我绝望了: - (
++ 这是我的#ideas.sdex.controller.js&#39;文件。
{user: {$ne: $stateParams.userId}}
{user: {$not: $stateParams.userId}}
{$ne: {user: $stateParams.userId}}
{$not: {user: $stateParams.userId}}
答案 0 :(得分:0)
gatherThoughtsIndex 和 userThoughtsIndex 路由从网址获取userId参数,但主路由不接受此类参数。
您的api调用将从stateProvider获取您生成的查询对象,并调用该服务器。但是,由于您没有在主路由中生成查询参数,因此您必须在没有任何查询参数的情况下进行api调用。
您必须以这种方式更新后端 -
我希望这对你有意义。 :)