devextreme-datagrid update:message:“(未知URL)的Http失败响应:0未知错误”

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了devextreme-datagrid update:message:“(未知URL)的Http失败响应:0未知错误”相关的知识,希望对你有一定的参考价值。

我无法更新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 => { });
}

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

{key:“5c6ac45adb48bf3850eebc74”,data:{...},component:inheritor,element:dx-data-grıd#gridContainer.dx-widget.dx-visibility-change-handler} component:inheritor {_events:{...},_ eventsStrategy :NgEventsStrategy,callBase:undefined,_ $ element:initRender(1),NAME:“dxDataGrid”,...} data:isKazasi:8 proto:Object element:dx-data-grıd#gridContainer.dx-widget.dx-visibility- change-handler key:“5c6ac45adb48bf3850eebc74”proto:Object

并给出一个错误:

{msg:'行更新操作',传入:{_ id:'5c6ac45adb48bf3850eebc74',isKartasi:8}}行更新错误:{“message”:NaN “at path ” “”,“name”:“CastError”,“stringValue”:“”NaN “”,“kind”:“number”,“value”:null,“path”:“absentism”

答案

该错误表示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;
}

以上是关于devextreme-datagrid update:message:“(未知URL)的Http失败响应:0未知错误”的主要内容,如果未能解决你的问题,请参考以下文章

Hive3的update速度

PHP MySQL Update 之 Update

svn update 可否只更新部分文件

update和insert + delete哪个更快?

SQL里面update 的用法

update和insert + delete哪个更快?