NodeJs Ajax CRUD jsgrid
У меня есть одна ошибка, когда я нажимаю кнопку удаления в моем представлении. В прошлом его работа была успешной, и теперь у меня возникла проблема.
Erreur: events.js: 160
throw er; // Unhandled 'error' event ^
TypeError: callback.apply не является функцией в Immediate. (D:\jsgrid- expressmaster\node_modules\mongoose\lib\model.js:4046:16)
Немедленно. (D: \ jsgrid-экспресс-мастер \node_modules\mquery\ Lib\utils.js:137:16)
при runCallback (timers.js:672:20)
в tryOnImmediate (timers.js: 645: 5)
at processImmediate [как _immediateCallback] (timers.js:617:5)
^
var express = require('express');
var router = express.Router();
var Categorie = require('../models/user'); //Categorie
var getClientFilter = function(query) {
var result = {
Name: new RegExp(query.Name, "i"),
Address: new RegExp(query.Address, "i")
};
if(query.Married) {
result.Married = query.Married === 'true' ? true : false;
}
if(query.Country && query.Country !== '0') {
result.Country = parseInt(query.Country, 10);
}
return result;
};
var prepareItem = function(source) {
var result = source;
result.Married = source.Married === 'true' ? true : false;
result.Country = parseInt(source.Country, 10);
return result;
};
router.get('/', function(req, res, next) {
Categorie.find(getClientFilter(req.query), function(err, items) {
res.json(items);
});
});
router.post('/', function(req, res) {
Categorie.create(prepareItem(req.body), function(err, item) {
res.json(item);
});
});
router.put('/', function(req, res, next) {
var item = prepareItem(req.body);
Categorie.update({ _id: item._id }, item, {}, function(err, item) {
res.json(item);
});
});
router.delete('/', function(req) {
var item = prepareItem(req.body);
Categorie.remove({ _id: item._id }, {}, function(err, item) {
res.json(item);
});
});
module.exports = router;
extends layout
block head
link(href='https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css', rel='stylesheet')
link(href='https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css', rel='stylesheet')
block content
div#jsGrid
block scripts
script(src='https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js')
script(src='/js/sample.js')
$(function() {
var countries = [
{ Name: "", Id: 0 },
{ Name: "United States", Id: 1 },
{ Name: "Canada", Id: 2 },
{ Name: "United Kingdom", Id: 3 },
{ Name: "France", Id: 4 },
{ Name: "Brazil", Id: 5 },
{ Name: "China", Id: 6 },
{ Name: "Russia", Id: 7 }
];
$("#jsGrid").jsGrid({
height: "70%",
width: "100%",
filtering: true,
inserting: true,
editing: true,
sorting: true,
paging: true,
autoload: true,
pageSize: 5,
pageButtonCount: 5,
deleteConfirm: "Do you really want to delete client?",
controller: {
loadData: function(filter) {
return $.ajax({
type: "GET",
url: "/clients",
data: filter
});
},
insertItem: function(item) {
return $.ajax({
type: "POST",
url: "/clients",
data: item
});
},
updateItem: function(item) {
return $.ajax({
type: "PUT",
url: "/clients",
data: item
});
},
deleteItem: function(item) {
return $.ajax({
type: "DELETE",
url: "/clients",
data: item
});
}
},
fields: [
{ name: "Name", type: "text", width: 150 },
{ name: "Age", type: "number", width: 50, filtering: false },
{ name: "Address", type: "text", width: 200 },
{ name: "Country", type: "select", items: countries, valueField: "Id", textField: "Name" },
{ name: "Married", type: "checkbox", title: "Is Married", sorting: false },
{ type: "control" }
]
});
});