如何通过忽略对象中的 isDeleted 标志来更新订单值

为什么webpack不支持静态字段?


当我尝试时


export class Game {

#lasttime = 0;

#FRAME_DURATION = 1000 / 144;

我收到一个错误


模块解析失败:意外字符“#”(2:4) 您可能需要适当的加载程序来处理此文件类型,当前没有配置加载程序来处理此文件。请参阅https://webpack.js.org/concepts#loaders。问题是什么?


const path = require('path');

const HTMLPlugin = require('html-webpack-plugin');


module.exports = {

  entry: './src/index.js',

  output: {

    filename: 'js/main.js',

    path: path.resolve(__dirname, 'dist'),

  },

  devtool: 'inline-source-map',

  devServer: {

    contentBase: './dist',

  },

  plugins: [

    new HTMLPlugin({

      template: './src/index.html'

    })

  ],

};


阿晨1998
浏览 93回答 2
2回答

Smart猫小萌

您可以对订单使用闭包,并在必要时进行更新。const data = [{id: 1, name: 'test1', order: 1}, {id: 2, name: 'qos1', isDeleted: true, order: 2}, {id: 3, name: 'qos2', order: 3}];data.forEach((order => o => {    if (!o.isDeleted) o.order = order++;})(1))console.log(data);

慕田峪7331174

创建一个 external counter,并且仅在该项目未被删除时才增加它:const arr = [{id: 1, name: 'test1', order: 1}, {id: 2, name: 'qos1', isDeleted: true, order: 2}, {id: 3, name: 'qos2', order: 3}]let counter = 1arr.forEach(item => {  item.order = counter    counter += !item.isDeleted // casting boolean to number false - 0, true - 1})console.log(arr)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript