devextreme-datagrid更新:消息:“对(未知URL)的HTTP故障响应:0未知错误”

时间:2019-02-18 19:31:35

标签: angular typescript datagrid devexpress devextreme

我在更新devextreme-datagrid时遇到问题。 你能帮忙吗?

lineController.js

 router.put("/:id", (req, res) => {
      if (!ObjectId.isValid(req.params.id))
        return res.status(400).send(`No record with given id : ${req.params.id}`);
      console.log({
        msg: "Line guncelleme işlemi",
        gelenveri: req.body
      });
      var emp = {
        bant: req.body.bant,
        tarih: req.body.tarih,
        isKazasi: req.body.isKazasi,
        ramakKala: req.body.ramakKala,
        tamirAdedi: req.body.tamirAdedi,
        ikinciKaliteAdedi: req.body.ikinciKaliteAdedi,
        sevkiyattanGelenHata: req.body.sevkiyattanGelenHata,
        diger: req.body.diger,
        koliCikisAdedi: req.body.koliCikisAdedi,
        planlananAdet: req.body.planlananAdet,
        sam: req.body.sam,
        calisilanToplamSure: req.body.calisilanToplamSure,
        bantKisiSayisi: req.body.bantKisiSayisi,
        ilaveCalisilanDk: req.body.ilaveCalisilanDk,
        iseGelmeyenlerinToplamSuresi: req.body.iseGelmeyenlerinToplamSuresi,
        hataOrani:
          ((req.body.tamirAdedi +
            req.body.ikinciKaliteAdedi +
            req.body.sevkiyattanGelenHata +
            req.body.diger) /
            (req.body.koliCikisAdedi + req.body.ikinciKaliteAdedi)) *
          100,
        ikinciKaliteOrani:
          (req.body.ikinciKaliteAdedi /
            (req.body.koliCikisAdedi + req.body.ikinciKaliteAdedi)) *
          100,
        planlamayaUyum: (req.body.koliCikisAdedi / req.body.planlananAdet) * 100,
        hatVerimliligi:
          (req.body.koliCikisAdedi * req.body.sam) /
          (req.body.calisilanToplamSure * req.body.bantKisiSayisi),
        ilaveCalisma: (req.body.ilaveCalisilanDk * req.body.bantKisiSayisi) / 60,
        devamsizlikYuzdesi:
          (req.body.iseGelmeyenlerinToplamSuresi / (req.body.bantKisiSayisi * 9)) * 100
      };
      Line.findByIdAndUpdate(
        req.params.id,
        { $set: emp },
        { new: true },
        (err, doc) => {
          if (!err) {
            res.send(doc);
          } else {
            console.log(
              "satır güncelleme hatası:" + JSON.stringify(err, undefined, 2)
            );
          }
        }
      );
    });

line.service.ts

import { Injectable } from '@angular/core';
import {HttpClient} from '@angular/common/http';

import {Line} from './line.model';
@Injectable({
  providedIn: 'root'
})
export class LineService {
  selectedLine: Line;
  lines: Line[];
  readonly baseURL = 'http://localhost:3000/lines';


  constructor(private http: HttpClient) { }


  postLine(emp: Line) {
    return this.http.post(this.baseURL, emp);
  }

  getLineList() {
    return this.http.get(this.baseURL);
  }

  // putLine(id, emp: Line) {
  //   return this.http.put(this.baseURL + `/${id}`, emp);
  // }
  putLine(emp: Line) {
    return this.http.put(this.baseURL + `/${emp._id}`, emp);
  }

  deleteLine(_id: string) {
    return this.http.delete(this.baseURL + `/${_id}`);
  }
}

line.component.html

<dx-data-grid
          id="gridContainer"
          [dataSource]="lineService.lines"
          title="SQDCM Veri Gİrişi"
          keyExpr="_id"
          [columnAutoWidth]="true"
          [showBorders]="true"
          (onRowInserted)="onEdit($event)"
          (onRowUpdated)="onUpdate($event)"
          (onRowRemoved)="onDelete($event)"
        > 

line.component.ts

onUpdate(event) {
  console.log(event);
  const merged = {_id: event.key, ...event.data};
   this.lineService.putLine(merged).subscribe(res => { });
}

当我更新数据时,它会将其写入控制台。

  

{键:“ 5c6ac45adb48bf3850eebc74”,数据:{…},组件:继承者,   元件:   dx-data-grıd#gridContainer.dx-widget.dx-visibility-change-handler}   组件:继承者{_events:{…},_ eventsStrategy:NgEventsStrategy,   callBase:未定义,_ $ element:initRender(1),NAME:“ dxDataGrid”,…}   数据:isKazasi:8    proto :对象元素:dx-data-grıd#gridContainer.dx-widget.dx-visibility-change-handler键:   “ 5c6ac45adb48bf3850eebc74”   原始:对象

并给出错误:

  

{消息:“ Line guncellemeişlemi”,gelenveri:{_id:   '5c6ac45adb48bf3850eebc74',isKazasi:8}} satrgüncellemehatası:{   “ message”:“路径上的值\” NaN \“的数字转换失败   \“ devamsizlikYuzdesi \”“,”名称“:” CastError“,” stringValue“:   “ \” NaN \“”,“种类”:“数字”,“值”:空,“路径”:   “ devamsizlikYuzdesi”}

1 个答案:

答案 0 :(得分:0)

该错误表明在devamsizlikYuzdesi的计算中存在以下问题

devamsizlikYuzdesi:(req.body.iseGelmeyenlerinToplamSuresi / (req.body.bantKisiSayisi * 9)) * 100 

我认为以下两个属性中的一个/都是未定义的

iseGelmeyenlerinToplamSuresibantKisiSayisi.

我相信检查那些值是否未定义,并向这些属性添加默认值(0)应该可以解决您的问题。

在var emp = {...

之前添加以下内容
if(req.body.iseGelmeyenlerinToplamSuresi == undefined){
    req.body.iseGelmeyenlerinToplamSuresi = 0;
}

if(req.body.bantKisiSayisi == undefined){
    req.body.bantKisiSayisi = 0;
}