RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-455477

Arteil's questions

Martin Hope
Arteil
Asked: 2024-12-18 18:04:31 +0000 UTC

按嵌套数组过滤

  • 6

有一个对象数组users,其中有另一个对象数组stations,如何使用函数arr.filter(x => ... )来查找具有station.id == 1

数组示例:

[{
    "id": 1603,
    "section": {
      "id": 2,
      "shop": 12
    },
    "employee": {
      "id": 152,
      "shop": 12,
      "stations": [],
      "certified_stations": [],
      "is_active": true
    },
    "cell": null,
    "row": null,
    "station": [{
        "id": 1,
        "project": 2
      },
      {
        "id": 2,
        "project": 2
      }
    ]
  },
  {
    "id": 1594,
    "section": {
      "id": 2,
      "shop": 12
    },
    "employee": {
      "id": 146,
      "shop": 12,
      "stations": [],
      "certified_stations": [],
      "is_active": true
    },
    "cell": null,
    "row": null,
    "station": [{
      "id": 2,
      "project": 2
    }]
  }
]
javascript
  • 1 个回答
  • 12 Views
Martin Hope
Arteil
Asked: 2024-08-29 17:19:02 +0000 UTC

构建 Radar Chart.js 图表

  • 6

有一个数据数组

            [88.331566, 161.26106],
            [267.78873, 69.070625],
            [61.81063, 200.0],
            [54.48104, 200.0],
            [48.937656, 200.0],
            [139.215, 70.5277],
            [105.86972, 234.48161],
            [111.62624, 220.65602],
            [12.477702, 197.3125],
            [40.90647, 146.83994],
            [39.692104, 147.6453],
            [11.931946, 91.9375],
            [112.736885, 147.54906],

使用它们你需要构建一个像这样的图表:日程

数组中的第一个值是角度(度)。第二,距图中心的距离。我正在尝试使用 Chart.js 来实现这一点,但也可以通过任何其他方式来完成。屏幕截图中的图表是这样构建的:

labels: [
    0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130,
    140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250,
    260, 270, 280, 290, 300, 310, 320, 330, 340, 350,
],
datasets: [
    {
        label: "Test",
        backgroundColor: "rgba(179,181,198,0.2)",
        borderColor: "rgba(179,181,198,1)",
        pointBackgroundColor: "rgba(179,181,198,1)",
        pointBorderColor: "#fff",
        pointHoverBackgroundColor: "#fff",
        pointHoverBorderColor: "rgba(179,181,198,1)",
        data: [
            0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130,
            140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250,
            260, 270, 280, 290, 300, 310, 320, 330, 340, 350
        ],
     },
 ],

问题在于,图的值也必须以数组的形式出现,按顺序排列,即一个标签元素只能有一个值,但根据任务,可以有多个,例如例如,在拐角 10 附近,值为 7 和 12

应该发生什么的视觉示例 应该发生什么的例子

javascript
  • 1 个回答
  • 38 Views
Martin Hope
Arteil
Asked: 2024-05-20 20:53:42 +0000 UTC

单击 div 元素外部

  • 5

有两种类型的自定义选择,可选择一个值和多个值。我使用 跟踪元素外部的点击@focusout。问题是,当您尝试通过单个选择在元素中选择一个值时,它会立即关闭、触发,@focusout并且每隔一段时间就会重新定义该值。同时,在具有多值的元素中,一切正常。

代码位于play.vuejs.org

在元素外部单击时是否有其他替代方法可以实现关闭?

更新。我意识到,如果您单击input,如果在输入之外,但在元素的边界处,则一切正常

vue.js
  • 1 个回答
  • 32 Views
Martin Hope
Arteil
Asked: 2024-05-15 21:05:29 +0000 UTC

带循环的函数无法正常工作

  • 5

该函数将商品添加到购物车。问题在于检查购物车中是否有相同的商品,但尺寸不同。

代码:

addCart(merch) {
  if(localStorage.getItem('cart')) {
    let array = JSON.parse(localStorage.getItem('cart'));

    for(let i = 0; i < array.length; i++) {
      if(merch.id === array[i].id && this.size === array[i].size) {
        array[i].count++
        localStorage.removeItem('cart')
        localStorage.setItem('cart', JSON.stringify(array));

      } else {
        let product = {
          id: merch.id,
          name: merch.real_name,
          image: merch.image,
          thumbnail: merch.thumbnail,
          price: merch.price,
          size: this.size,
          count: 1
        }

        array.push(product)
        localStorage.setItem('cart', JSON.stringify(array));
      }
    }
  } else {
    let array = []
    let product = {
      id: merch.id,
      name: merch.real_name,
      image: merch.image,
      thumbnail: merch.thumbnail,
      price: merch.price,
      size: this.size,
      count: 1
    }

    array.push(product)

    localStorage.setItem('cart', JSON.stringify(array));
  }
}

我需要的一个例子:

[
    {
       id: 0,
       name: Продукт 1,
       size: S,
       count: 2
    },
    {
       id: 1,
       name: Продукт 2,
       size: XS,
       count: 1
    }
]

我得到:

[
    {
       id: 0,
       name: Продукт 1,
       size: S,
       count: 2
    },
    {
       id: 0,
       name: Продукт 1,
       size: S,
       count: 2
    },
    {
       id: 1,
       name: Продукт 2,
       size: XS,
       count: 1
    }
]

在这里您可以看到该函数的行为方式 https://playcode.io/

javascript
  • 1 个回答
  • 38 Views
Martin Hope
Arteil
Asked: 2024-03-01 20:20:37 +0000 UTC

[Vue warn]:写入操作失败:计算属性为只读

  • 5

有一个employees从 vuex 传递过来的对象变量state。

computed: {
    ...mapState ({
        employee: state => state.day.employees,
    }),
},

当你尝试改变这个对象时

this.employee = this.employee.map(x => {
    if(x.id === itemId) {
        x.cell_id = cell_id
    }
    return x
})

出现错误[Vue warn]: Write operation failed: computed property "employee" is readonly.:如何使该对象可更改?

javascript
  • 1 个回答
  • 22 Views
Martin Hope
Arteil
Asked: 2023-04-05 21:39:00 +0000 UTC

如何在axios函数中返回值

  • 5

有一个带有axios请求的函数,当它被调用时,它返回Promise。我需要true/false

async checkPermission ({}, rolename) {
    try {
        const response = await $http.get('/check/role?rolename='+rolename)
        if(response.data.role_required) {
            return true
        }
    } catch (err) {
        alert(err)
    }
 }

尝试调用它时console.log(this.checkPermission('Администратор'))

我得到

函数调用结果

javascript
  • 1 个回答
  • 24 Views
Martin Hope
Arteil
Asked: 2022-08-21 15:17:19 +0000 UTC

在 <select> 中查找元素

  • 0

有一个列表搜索<select>可以隐藏所有与搜索中输入的内容不匹配的项目。但是有一个问题,当在一个大列表(4500 个元素)中搜索时,它会挂起几秒钟。您还可以搜索或优化哪些其他方式?

document.addEventListener("click", function(e) {
    let input = document.getElementById(dataTargetID + 'Input'); 
    let val = input.value.trim().toUpperCase();
    let searchItems = document.querySelectorAll('#'+dataTargetID + ' option');
    if (e.target.classList.contains('keyboard__key')) {
        if (val != '') {
            searchItems.forEach(function (elem){
                if (elem.innerText.toUpperCase().search(val) == -1) {
                    elem.classList.add('hidden')
                }
                else {
                    elem.classList.remove('hidden');
                }
            });
        }
        else {
            searchItems.forEach(function (elem){
                elem.classList.remove('hidden');
            });
        }
    }
})
javascript html
  • 2 个回答
  • 83 Views
Martin Hope
Arteil
Asked: 2022-07-27 15:38:09 +0000 UTC

JSON 错误 - JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig)

  • 0

您需要阅读 JSON 文件。抛出一个错误json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)

这是代码的样子:

def getJSON(self):
    json_file = 'http://192.168.31.194:8000/static/files/09IPL.json'
    res_json = requests.get(json_file).text
    
    return res_json
    
def jsonParse(self):
    res_json = self.getJSON()
    data = json.loads(res_json)
    
    return res_json

格式的 JSON 文件:

{"Название": [
{
  "Физлицо": "ФИО",
  "Подразделение": "подразделение",
  "Должность": "должность"
}]}
python
  • 2 个回答
  • 104 Views
Martin Hope
Arteil
Asked: 2022-07-05 13:38:20 +0000 UTC

favicon.ico 被分配给一个 Flask 变量

  • 0

有路由功能

@app.route('/<string:tpaIndex>')
      def mainView(tpaIndex):
         return render_template('index.html',tpaIndex=tpaIndex)

不知何故,一个tpaIndex字符串进入了变量,地址栏中输入的值应该被分配给该变量,favicon.ico这发生在GET服务器处理请求之后,[05/May/2022 08:32:22] "GET /favicon.ico HTTP/1.1" 500 - 如何处理?由于某种原因,以前没有这样的问题,它是凭空出现的

python веб-программирование
  • 1 个回答
  • 25 Views
Martin Hope
Arteil
Asked: 2022-06-19 13:47:20 +0000 UTC

用空字符串Python替换请求中的所有None

  • 0

查询数据库时,空单元格被转换为 None 并且也显示在页面上。我需要将每个单元格从 None 替换为空字符串。这是一段带有请求的现有代码

        for id in tpaList:
        cursor = self.connections['DB_Name'].execute(f''' SELECT *
                                                            FROM [DB_Name].[dbo].[Table_Name]
                                                                AND EndDate IS NULL
                                                            ORDER BY StartDate DESC ''')
        columns = [column[0] for column in cursor.description]
        for row in cursor.fetchall():
            idleJournal.append(dict(zip(columns, row))) 
    return idleJournal
python sql
  • 1 个回答
  • 46 Views
Martin Hope
Arteil
Asked: 2022-05-09 15:43:36 +0000 UTC

单击表格中的最后一个单元格

  • 1

有一个通过 PHP 填充的表:

<table id="position">
  <thead>
    <tr>
      <th scope="col">ID</th>
      <th scope="col">Статус</th>
      <th scope="col">IP-адрес</th>
      <th scope="col">Последняя активность</th>
      <th scope="col"></th>
    </tr>
  </thead>
  <tbody>
    <tr id='{$ip}'>
      <th scope='row'>{$id}</th>
      <td>{$online}</td>
      <td><a href='http://{$ip}' target='_blank'>{$ip}</a></td>
      <td>{$lastActive}</td>
      <td id='button'><i class='bi bi-trash' style='font-size: 20px' ;></i></td>
    </tr>";
  </tbody>
</table>

有点击表格行的跟踪:

const tbody = document.querySelector('#position tbody');
tbody.addEventListener('click', function (e) {
const cell = e.target.closest('td');
if (!cell) {return;} // Quit, not clicked on a cell
const row = cell.parentElement;
console.log(row.rowIndex, row.id);

问题是该函数跟踪对表格整行的点击,而我只需要最后一个单元格(带有id='button')。我尝试了几个选项 - 没有任何帮助 - 只跟踪了第一行的单元格,其余的被忽略了。

javascript
  • 2 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5