小编CJe*_*CJe的帖子

来自post请求的有效负载在node.js函数中不可用

我刚刚开始使用三个新的(对我来说)框架/产品:MongoDB,NodeJS和AngularJS.

我想要完成的是让一个简单的表单提交一个值并将该值写入数据库.我已经达到了一个点,我的Angular应用程序中使用$ http.post提交了我的值,我确实调用了我的node.js后端函数,但我的req参数(如下所示)未定义.从Google Chromes网络监视器我可以看到提交了POST请求,并且有效负载包含我输入的值.

我真的不明白为什么它在接收端不可用.请帮忙.

现在为一些片段(而不是整个文件):

server.js:

var express = require('express'),
menu = require('./routes/menu'),
http = require('http'),
app = express(),
httpServer = http.createServer(app),
bodyParser = require('body-parser');

app.use(bodyParser.json());

app.set('port', 3000);

app.use(express.static(__dirname));

app.get('/menuItems', menu.getMenuItems);
app.post('/menuItems', function(req, res) { console.log(req); });

httpServer.listen(app.get('port'), function () {
    console.log("Express server listening on port %s.", httpServer.address().port);
});
Run Code Online (Sandbox Code Playgroud)

menu.js:

exports.addMenuItem = function(req, res) {
var menuItem = req.body;  <===req.body is undefined
console.log('Adding menuItem: ' + JSON.stringify(menuItem)); 

db.collection('menuItems', function(err, collection) {
    collection.insert(menuItem, {safe:true}, function(err, result) {
        if (err) { …
Run Code Online (Sandbox Code Playgroud)

node.js angularjs

4
推荐指数
1
解决办法
7436
查看次数

如何在jQuery中处理嵌套事件

我有一个

<span class="fold"></span>
Run Code Online (Sandbox Code Playgroud)

这是由一个

$('.fold').click(function (event) { ... });
Run Code Online (Sandbox Code Playgroud)

现在click事件通过ajax添加新的"fold"类,我想将相同的事件处理程序分配给.这是可能的,如果是这样,在逻辑中我会"重新" - 添加我的点击处理程序?

提前致谢

jquery events nested

2
推荐指数
1
解决办法
1514
查看次数

无法从适配器中的getView返回两个不同的视图

开发我的第一个应用程序我正在尝试在列表视图中向我的元素添加部分.所有项目都有一个日期,我希望每次日期更改时返回一个包含日期的简单布局.在我的适配器中,我有以下内容:

    public View getView(int position, View convertView, ViewGroup parent) {
    Match match = matchArrayList.get(position);
    Calendar matchTime = match.getDate();
    SimpleDateFormat date = new SimpleDateFormat("dd-MM-yyyy");
    SimpleDateFormat time = new SimpleDateFormat("HH:mm"); 
    String sDate = date.format(matchTime.getTime());
    SeparatorHolder separatorHolder = null;
    MatchHolder matchHolder = null;

    if (convertView == null) {
        if (!sDate.equals(_lastDate)) {
            convertView = inflator.inflate(R.layout.date_separator, null);
            separatorHolder = new SeparatorHolder();
            separatorHolder.Date = (TextView) convertView.findViewById(R.id.date);
            convertView.setTag(separatorHolder);
        } else {
            convertView = inflator.inflate(R.layout.match_layout, null);
            matchHolder = new MatchHolder();
            matchHolder.Time = (TextView) convertView.findViewById(R.id.time);
            matchHolder.HomeTeam = (TextView) convertView.findViewById(R.id.homeTeam); …
Run Code Online (Sandbox Code Playgroud)

android android-adapter

1
推荐指数
1
解决办法
3120
查看次数

集合作为字典中的关键

我有一个这样的字典:

var dic = Dictionary<Collection<MyObject>, string>
Run Code Online (Sandbox Code Playgroud)

然后我添加一个这样的条目:

dic.Add(myObjColl, "1");
Run Code Online (Sandbox Code Playgroud)

其中myObjColl包含单个条目

在第二次运行时,我尝试向dic添加另一个条目,其中myObjColl有两个条目(其中一个与第一次运行中的条目相同),并且我得到一个异常,即密钥已经存在.

我在这里错过了什么?我希望字典键是一个集合,当然两个具有不同条目数的集合不能相同.

编辑:发生了什么是myObjColl在foreach之外初始化并在第二次迭代期间更新.所以我认为是一个带有两个条目的新集合实际上是旧的一个条目集合,并添加了一个额外的条目.

详细说明我的问题:

我有一组产品行对象.每个都有一个产品标识对象,由一组键值对组成:

Collection<ProductKeyValuePair> productIdentification;
myProductRow.ProductIdentification = productIdentification;
Run Code Online (Sandbox Code Playgroud)

然后我必须构建另一个ProductKeyValuePairs集合,定义每个产品行对象的"所有者"(一个产品行对象可以有多个所有者),我需要将每个所有者添加到对应的procuct行对象.传统的多对多,其中公共密钥是KeyValuePairs的集合.

很难解释,但它实际上取决于在大型机上运行的旧系统返回的遗留数据,并且很可能存储在某种分层数据库中: - /

c# dictionary

1
推荐指数
1
解决办法
121
查看次数