感谢您一看。
这是我的代码:
来自models / Cart.js
import matplotlib.pyplot as plt
import matplotlib.gridspec as gspec
import numpy as np
fig = plt.figure()
gs = gspec.GridSpec(2, 2)
gs.update(hspace=0.7, wspace=0.7)
ax1 = plt.subplot(gs[0, 0])
ax2 = plt.subplot(gs[1, 0])
ax3 = plt.subplot(gs[0, 1])
ax4 = plt.subplot(gs[1, 1])
x1 = np.linspace(1,10,10)
ax1.plot(x1, x1**2)
ax1.set_xlabel('ax1 x')
ax1_2 = ax1.twinx()
ax1_2.plot(x1, x1**3)
ax1_2.set_ylabel('ax1_2 y')
ax1.set_ylabel('ax1 y')
# To save time I left the other cells blank, but it should work fine.
plt.show()
来自cart.js
var mongoose = require('mongoose');
var CartSchema = mongoose.Schema({
owner: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
products: [ {type: mongoose.Schema.Types.ObjectId, ref: 'Product', quantity: Number} ],
created: Date,
updated: Date
});
exports.Cart = mongoose.model('Cart', CartSchema);
我得到的错误是var model = require('../models/Cart');
//modify a cart
router.post('/update/:id', function(req, res, next){
var cart = model.Cart();
console.log(cart);
cart.findByIdAndUpdate(req.params.id, {
products: req.body.products,
updated: moment().format()
}, {new:true}, function(err, result){
if(err) throw err;
res.status(200).send(result);
});
});
,位于cart.findByIdAndUpdate,购物车记录为undefined is not a function
。
答案 0 :(得分:1)
尝试删除或评论此行:ControllerAs
并在行//var cart = model.Cart();
上将cart
替换为model
。