花间憩

文章 评论 浏览 31

花间憩 2025-02-10 06:04:19

基于您的答案,我将代码抽象为指令,因此更清晰,因此无需处理事件:

import { Directive, ElementRef } from '@angular/core';

@Directive({
  selector: '[appAutoFocus]'
})
export class AutoFocusDirective {

  constructor(private elementRef: ElementRef) {

    // Create non-visible temporary input element and focus it
    const tmpElement = document.createElement('input');
    tmpElement.style.width = '0';
    tmpElement.style.height = '0';
    tmpElement.style.margin = '0';
    tmpElement.style.padding = '0';
    tmpElement.style.border = '0';
    tmpElement.style.opacity = '0';
    document.body.appendChild(tmpElement);
    tmpElement.focus();

    setTimeout(() => {
      // Focus the main (input) element, thus opening iOS keyboard
      this.elementRef.nativeElement.focus();
      document.body.removeChild(tmpElement);
    }, 0);
  }
}

只需使用它 :在您的输入元素中:

<input type="text" appAutoFocus>

Based on your answer, I abstracted the code into a directive so it's clearer and there's no need to handle events:

import { Directive, ElementRef } from '@angular/core';

@Directive({
  selector: '[appAutoFocus]'
})
export class AutoFocusDirective {

  constructor(private elementRef: ElementRef) {

    // Create non-visible temporary input element and focus it
    const tmpElement = document.createElement('input');
    tmpElement.style.width = '0';
    tmpElement.style.height = '0';
    tmpElement.style.margin = '0';
    tmpElement.style.padding = '0';
    tmpElement.style.border = '0';
    tmpElement.style.opacity = '0';
    document.body.appendChild(tmpElement);
    tmpElement.focus();

    setTimeout(() => {
      // Focus the main (input) element, thus opening iOS keyboard
      this.elementRef.nativeElement.focus();
      document.body.removeChild(tmpElement);
    }, 0);
  }
}

Just use it in your input element:

<input type="text" appAutoFocus>

专注于Angular以后的输入(模态显示)之后,在Safari iOS中显示键盘

花间憩 2025-02-10 05:53:18

您的输入具有不同的id属性,但它们都具有相同的name。正是name确定提交的内容,因为您已经在编写此行时就已经发现了未意识到的那样:

<?php if (isset($_POST['switch_sticker'])){echo 'checked="checked"';}?>

如果语句中没有任何内容,则围绕循环有所不同;它每次都查看相同的值$ _ post ['switch_sticker']

同时,JavaScript代码本质上与问题无关,因为它仅更改各种元素的value。这些将显示为$ _ post ['switch_sticker']变量的值,但是由于只有一个变量和大量值,因此最终将出现列表中的最后一个。

解决方案是给您每个复选框自己的name,就像您给他们自己的valuename =“ switch_sticker_&lt;?= $ key?gt; “。然后在php中查找该名称:&lt;?php if(ISSET($ _ post ['switch_sticker_'。$ key]。 。

您还可以在form 中使用名称某物[sosity_else],例如name =“ switch_sticker [&lt;?= $键?&gt;] ?这会导致PHP提交时创建 array ,这要好得多 - 您可以写foreach($ _post ['switch_sticker'] as $ nistkitykey,它可以编写诸如=&gt; $提交值){...}

Your inputs have different id attributes, but they all have the same name. It is the name that determines what gets submitted, as you have already discovered without realising it when you wrote this line:

<?php if (isset($_POST['switch_sticker'])){echo 'checked="checked"';}?>

That if statement has nothing in it which varies around the loop; it looks at the same value $_POST['switch_sticker'] every time.

The JavaScript code, meanwhile, is essentially irrelevant to the question, because it only changes the value of various elements. Those will show up as the value of the $_POST['switch_sticker'] variable, but because there's only one variable and lots of values, it will just end up with the last one in the list.

The solution is to give each of your checkboxes their own name, like you give them their own value: name="switch_sticker_<?=$key?>". Then look for that name in the PHP: <?php if (isset($_POST['switch_sticker_' . $key])){echo 'checked="checked"';}?>.

You can also use names in the form something[something_else], e.g. name="switch_sticker[<?=$key?>]" and <?php if (isset($_POST['switch_sticker'][$key])){echo 'checked="checked"';}?>. That will cause PHP to create an array when they're submitted, which is a bit nicer to work with - you can write things like foreach ( $_POST['switch_sticker'] as $submittedKey => $submittedValue ) { ... }.

为什么在jQuery帖子后检查所有输入?

花间憩 2025-02-09 15:27:09

这就是为什么我们不应该将DART中的地图用作数据结构的原因之一,因为它使表达元素彼此相等的含义相当复杂。

因此,我建议通过创建user类这样的类来解决此问题:

class User {
  String name;
  String user_id;

  User({required this.name, required this.user_id});

  @override
  int get hashCode => user_id.hashCode;

  @override
  bool operator ==(Object other) => other is User && user_id == other.user_id;

  @override
  String toString() => '{Name: $name, User ID: $user_id}';
}
class User {
  String name;
  String user_id;

  User({required this.name, required this.user_id});

  @override
  int get hashCode => Object.hash(name, user_id);

  @override
  bool operator ==(Object other) =>
      other is User && name == other.name && user_id == other.user_id;

  @override
  String toString() => '{Name: $name, User ID: $user_id}';
}

通过这样做,我们可以做:

void main() {
  List<User> userList = [
    User(name: 'john', user_id: '251'),
    User(name: 'will', user_id: '255'),
    User(name: 'jack', user_id: '251'),
  ];

  userList.forEach(print);
  // {Name: john, User ID: 251}
  // {Name: will, User ID: 255}
  // {Name: jack, User ID: 251}
}

然后我们可以执行toset()这样的技巧:

void main() {
  List<User> userList = [
    User(name: 'john', user_id: '251'),
    User(name: 'will', user_id: '255'),
    User(name: 'jack', user_id: '251'),
  ];
  List<User> uniqueUserList = userList.toSet().toList();
  uniqueUserList.forEach(print);
  // {Name: john, User ID: 251}
  // {Name: will, User ID: 255}
}

我注意到您的示例是制作的,因此您仅查看user_id以确定是否具有重复元素。 不知道您的示例是否只是错误

class User {
  String name;
  String user_id;

  User({required this.name, required this.user_id});

  @override
  int get hashCode => Object.hash(name, user_id);

  @override
  bool operator ==(Object other) =>
      other is User && name == other.name && user_id == other.user_id;

  @override
  String toString() => '{Name: $name, User ID: $user_id}';
}

我 定义对其进行的定义:

void main() {
  List<Map<String, String>> userList = [
    {'name': 'john', 'user_id': '251'},
    {'name': 'will', 'user_id': '255'},
    {'name': 'jack', 'user_id': '251'} // duplicate
  ];

  final set = LinkedHashSet<Map<String, String>>(
    equals: (map1, map2) {
      final id1 = map1['user_id'];
      final id2 = map2['user_id'];

      return id1 != null && id2 != null && id1 == id2;
    },
    hashCode: (map) => map['user_id'].hashCode,
  );
  
  set.addAll(userList);
  
  List<Map<String, String>> uniqueUserList = set.toList();
  uniqueUserList.forEach(print);
  // {name: john, user_id: 251}
  // {name: will, user_id: 255}
}

使用MAP对象解决此问题,您可以使用以下以下在其中创建set的 这总是有点丑陋,因为MAP不适用于以前所述的数据结构。

This is one of the reasons why we should not use maps in Dart as data structures since it makes it rather complicated to express what it means for elements to be equal to each other.

So I would suggest solving this issue by creating a User class like this:

class User {
  String name;
  String user_id;

  User({required this.name, required this.user_id});

  @override
  int get hashCode => user_id.hashCode;

  @override
  bool operator ==(Object other) => other is User && user_id == other.user_id;

  @override
  String toString() => '{Name: $name, User ID: $user_id}';
}
class User {
  String name;
  String user_id;

  User({required this.name, required this.user_id});

  @override
  int get hashCode => Object.hash(name, user_id);

  @override
  bool operator ==(Object other) =>
      other is User && name == other.name && user_id == other.user_id;

  @override
  String toString() => '{Name: $name, User ID: $user_id}';
}

By doing so, we can do:

void main() {
  List<User> userList = [
    User(name: 'john', user_id: '251'),
    User(name: 'will', user_id: '255'),
    User(name: 'jack', user_id: '251'),
  ];

  userList.forEach(print);
  // {Name: john, User ID: 251}
  // {Name: will, User ID: 255}
  // {Name: jack, User ID: 251}
}

And we can then do the toSet() trick like this:

void main() {
  List<User> userList = [
    User(name: 'john', user_id: '251'),
    User(name: 'will', user_id: '255'),
    User(name: 'jack', user_id: '251'),
  ];
  List<User> uniqueUserList = userList.toSet().toList();
  uniqueUserList.forEach(print);
  // {Name: john, User ID: 251}
  // {Name: will, User ID: 255}
}

I notice that your example is made so you are only looking at the user_id to determine if you have a duplicate element. I don't know if your example is just wrong but if you want to compare both name and user_id your class would look like this:

class User {
  String name;
  String user_id;

  User({required this.name, required this.user_id});

  @override
  int get hashCode => Object.hash(name, user_id);

  @override
  bool operator ==(Object other) =>
      other is User && name == other.name && user_id == other.user_id;

  @override
  String toString() => '{Name: $name, User ID: $user_id}';
}

And finally, if you really want to solve this using Map objects, you could solve it using the following where you create a Set with your own definition of what it means to be equal:

void main() {
  List<Map<String, String>> userList = [
    {'name': 'john', 'user_id': '251'},
    {'name': 'will', 'user_id': '255'},
    {'name': 'jack', 'user_id': '251'} // duplicate
  ];

  final set = LinkedHashSet<Map<String, String>>(
    equals: (map1, map2) {
      final id1 = map1['user_id'];
      final id2 = map2['user_id'];

      return id1 != null && id2 != null && id1 == id2;
    },
    hashCode: (map) => map['user_id'].hashCode,
  );
  
  set.addAll(userList);
  
  List<Map<String, String>> uniqueUserList = set.toList();
  uniqueUserList.forEach(print);
  // {name: john, user_id: 251}
  // {name: will, user_id: 255}
}

There are other ways to solve this but it will always get kinda ugly since Map is not intended for data structures as previous described.

显示无重复/重复的地图列表-DART

花间憩 2025-02-08 19:15:13

更新

以下是做您问题提出的方法:

import pandas as pd
data = pd.DataFrame([pd.Series([k for k in range(10)]) for j in range(5)] for i in range(8))
ni, nj = data.shape
nk = len(data.loc[0, 0])
print(ni, nj, nk)

data2 = data.applymap(lambda x: x[:len(x) // 2])
print(*data2.shape, len(data2.loc[0, 0]))

输出:

8 5 10
8 5 5

如果您的数据位于3D Numpy数组中,则实际上可以切成3D数组。

这是一个往返pandas-to-numpy to-pandas解决方案:

import pandas as pd
import numpy as np
data = pd.DataFrame([pd.Series([k for k in range(10)]) for j in range(5)] for i in range(8))
ni, nj = data.shape
nk = len(data.loc[0, 0])
print(ni, nj, nk)

xf = [y.to_numpy() for y in data.to_numpy().flatten()]
n = np.array(xf).reshape([ni, nj, nk])
print(n.shape)
print(n)

n2 = n[:, :, :nk // 2]
print(n2.shape)
print(n2)

data2 = pd.DataFrame([pd.Series(n2[i, j, :]) for j in range(n2.shape[1])] for i in range(n2.shape[0]))
ni, nj = data2.shape
nk = len(data2.loc[0, 0])
print(ni, nj, nk)

这是从包含k-Length系列值的IXJ dataframe转换为3D numpy阵列n的输入:

[[[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]]

这是3D Numpy Array N2具有原始3D阵列(NK // 2)的一半的k- extent:

[[[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]]

作为最后一步,切成3D Numpy Array n2是转换回包含长度NK // 2的串联值的IXJ数据框。

UPDATED:

Here is a way to do what your question asks:

import pandas as pd
data = pd.DataFrame([pd.Series([k for k in range(10)]) for j in range(5)] for i in range(8))
ni, nj = data.shape
nk = len(data.loc[0, 0])
print(ni, nj, nk)

data2 = data.applymap(lambda x: x[:len(x) // 2])
print(*data2.shape, len(data2.loc[0, 0]))

Output:

8 5 10
8 5 5

If your data were in a 3D numpy array, it would be possible to actually slice the 3D array.

Here is a round-trip pandas-to-numpy-to-pandas solution:

import pandas as pd
import numpy as np
data = pd.DataFrame([pd.Series([k for k in range(10)]) for j in range(5)] for i in range(8))
ni, nj = data.shape
nk = len(data.loc[0, 0])
print(ni, nj, nk)

xf = [y.to_numpy() for y in data.to_numpy().flatten()]
n = np.array(xf).reshape([ni, nj, nk])
print(n.shape)
print(n)

n2 = n[:, :, :nk // 2]
print(n2.shape)
print(n2)

data2 = pd.DataFrame([pd.Series(n2[i, j, :]) for j in range(n2.shape[1])] for i in range(n2.shape[0]))
ni, nj = data2.shape
nk = len(data2.loc[0, 0])
print(ni, nj, nk)

Here is the input converted from an i x j dataframe containing k-length Series values to a 3D numpy array n:

[[[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]

 [[0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]
  [0 1 2 3 4 5 6 7 8 9]]]

Here is the 3D numpy array n2 which has a k-extent of half that of the original 3D array (nk // 2):

[[[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]

 [[0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]
  [0 1 2 3 4]]]

As a final step, the sliced 3D numpy array n2 is converted back to an i x j dataframe containing Series values of length nk // 2.

切成3D PANDAS DATADFRAME

花间憩 2025-02-08 09:33:53

我在github中找到了这个问题:
https://github.com/azure/azure/azure-storage-scopopy/assues/sissus/ 903

如GitHub链接中所述,我能够通过在ENV变量下设置AZCOPY工作。

mkdir /opt/myapp/azlogs
export AZCOPY_LOG_LOCATION=/opt/myapp/azlogs

这基本上是AZCOPY的日志位置。我正在考虑使此ENV变量的一部分成为图像的一部分,而不必每次将其输入。

编辑1:
我遇到了另一个错误。

panic: mkdir plans: permission denied

看来Azcopy想要在当前工作DIR上创建计划目录。因此,请确保您正在运行AZCOPY的用户以及在当前工作DIR上创建新文件夹的权限。

I found the issue in github:
https://github.com/Azure/azure-storage-azcopy/issues/903

I was able to get azcopy working by setting below env variable as mentioned in the github link.

mkdir /opt/myapp/azlogs
export AZCOPY_LOG_LOCATION=/opt/myapp/azlogs

This is basically the log location for azcopy. I'm thinking of making this env variable part of the image rather than having to type it out every time.

EDIT 1:
I came across another error.

panic: mkdir plans: permission denied

looks like azcopy wants to create a plans directory on current working dir. So ensure that the user you are running azcopy as has permissions to create a new folder on the current working dir.

AZCOPY在容器错误上安装 - “恐慌:Mkdir:否此类文件或目录”

花间憩 2025-02-08 00:24:33

您可以应用内置str.Str.Stripstr.rstrip(右侧带)和str.l.lstrip(左侧)的矢量化版本)使用pandas.series.str

​:

s.str.lstrip('[').str.rstrip(']')

You can apply a vectorized version of the builtin str.strip, str.rstrip (right side strip), and str.lstrip (left side strip) using the pandas.Series.str string methods:

Brackets on either side of each string element can be removed with the following:

s.str.lstrip('[').str.rstrip(']')

从大熊猫系列中删除方括号。 *多个列表元素

花间憩 2025-02-07 21:32:58

您必须在插入图像之前导入该图像是否来自目录而不是链接。

这样:

import logo from './logo.png'

然后您像这样插入它:

<img src={logo} alt="Logo" />

you have to import the image before inserting if it's coming from a directory and not a link.

like this:

import logo from './logo.png'

then you insert it like this:

<img src={logo} alt="Logo" />

图像未在网页上显示UO

花间憩 2025-02-07 13:55:12

我不能错过这个机会插入乔什·布洛克(Josh Bloch)的书有效的java 版)。第10章是Java序列化的不可或缺的资源。

根据Josh,自动生成的UID是基于类名称,实现的接口以及所有公共和受保护的成员生成的。以任何方式更改这些中的任何一个都会更改serialversionuid。因此,您不需要仅当您确定不超过一个版本的班级将被序列化(跨进程或以后从存储中检索)时,就不需要与他们混乱。

如果您暂时忽略它们,并以后发现您需要以某种方式更改类,但请维持类的兼容性,则可以使用JDK工具 serialver 来生成serialversionuid old 类上,并​​在新类中明确设置该>。 (根据您的更改,您可能需要还需要通过添加writeObjectreadObject方法来实现自定义序列化 - 请参见serializable javadoc或上述第10章。

I can't pass up this opportunity to plug Josh Bloch's book Effective Java (2nd Edition). Chapter 10 is an indispensible resource on Java serialization.

Per Josh, the automatically-generated UID is generated based on a class name, implemented interfaces, and all public and protected members. Changing any of these in any way will change the serialVersionUID. So you don't need to mess with them only if you are certain that no more than one version of the class will ever be serialized (either across processes or retrieved from storage at a later time).

If you ignore them for now, and find later that you need to change the class in some way but maintain compatibility w/ old version of the class, you can use the JDK tool serialver to generate the serialVersionUID on the old class, and explicitly set that on the new class. (Depending on your changes you may need to also implement custom serialization by adding writeObject and readObject methods - see Serializable javadoc or aforementioned chapter 10.)

什么是序列化uID,为什么要使用它?

花间憩 2025-02-07 06:19:28

我认为下面答案来自雷诺·塔内克(Renaud Tarnec)肯定会为您提供帮助。

如果您查看“调整图像”扩展程序的A>,您会看到构成构成扩展的云函数是由a onfinalize 事件,这意味着:

当新对象(或现有对象的新一代)是
成功创建的存储桶。这包括复制或重写
现有对象。

因此,如果不重写/再生现有图像,则不会触发扩展名。

但是,您可以轻松地编写自己的云功能,该功能可以执行相同的操作,但可以通过调用特定URL触发( https云功能)或通过在临时firestore集合中创建新文档(背景触发cf )。

该云功能将执行以下步骤:

  1. 获取存储桶的所有文件,请参阅 getfiles> ()
    Google Cloud Storage Node.js客户端API。此方法返回
    getfilesresponse object object 是文件实例的阵列。
  2. 通过在数组上循环,对于每个文件,请检查文件是否具有
    在存储桶中相应的调整大小图像(取决于您的方式
    配置了扩展名,调整大小的图像可能是特定的
    文件夹)
  3. 如果文件没有相应的调整大小映像,请执行
    该文件的扩展云功能的相同业务逻辑。

有一个官方的云功能 sample 显示如何创建如何创建云存储触发的firebase函数将创建从上传的映像创建调整大小的缩略图并将其上传到数据库URL(请参阅index.js file的最后一行)

注意:如果您有很多可以处理的文件,则可能很可能有效通过批处理,由于云功能执行的限制为9分钟。另外,根据要处理的图像数量,您可能需要增加超时值和/或云功能分配的内存,请参见 https://firebase.google.com/docs/functions/manage-functions/manage-functions#sety_time_time_time_and_and_memory_allocation

I think the below answer from Renaud Tarnec will definitely help you.

If you look at the code of the "Resize Images" extension, you will see that the Cloud Function that underlies the extension is triggered by a onFinalize event, which means:

When a new object (or a new generation of an existing object) is
successfully created in the bucket. This includes copying or rewriting
an existing object.

So, without rewriting/regenerating the existing images the Extension will not be triggered.

However, you could easily write your own Cloud Function that does the same thing but is triggered, for example, by a call to a specific URL (HTTPS cloud Function) or by creating a new document in a temporary Firestore Collection (background triggered CF).

This Cloud Function would execute the following steps:

  1. Get all the files of your bucket, see the getFiles() method of the
    Google Cloud Storage Node.js Client API. This method returns a
    GetFilesResponse object which is an Array of File instances.
  2. By looping over the array, for each file, check if the file has a
    corresponding resized image in the bucket (depending on the way you
    configured the Extension, the resized images may be in a specific
    folder)
  3. If a file does not have a corresponding resized image, execute the
    same business logic of the Extension Cloud Function for this File.

There is an official Cloud Function sample which shows how to create a Cloud Storage triggered Firebase Function that will create resized thumbnails from uploaded images and upload them to the database URL, (see the last lines of index.js file)

Note : If you have a lot of files to treat, you should most probably work by batch, since there is a limit of 9 minutes for Cloud Function execution. Also, depending on the number of images to treat, you may need to increase the timeout value and/or the allocated memory of your Cloud Function, see https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation

调整存储在Firebase存储中的所有现有图像,并通过API调用更新新调整大小的图像URL到数据库

花间憩 2025-02-07 05:08:03
const data= [ 
      "the lions of teranga",
      "tiger woods",
      "The Truman Show",
      "Shutter Island",
      "The Gold Rush",
  ]
inputData = "lions"
let a = data.filter(e => {
    str = e.toLowerCase()
    if (str.match(inputData.toLowerCase())){
        return e
    }
})
console.log(a)

此处过滤器返回返回的对象。在这里,您可以通过任何单词或字符搜索并作为数组返回。

const data= [ 
      "the lions of teranga",
      "tiger woods",
      "The Truman Show",
      "Shutter Island",
      "The Gold Rush",
  ]
inputData = "lions"
let a = data.filter(e => {
    str = e.toLowerCase()
    if (str.match(inputData.toLowerCase())){
        return e
    }
})
console.log(a)

Here filter returns the objects which are returned true. Here you can search by any word or character and return as an array.

在数组中的前两个字母中搜索数组中的前两个字母

花间憩 2025-02-06 20:56:00

不,请参见; min_samples_split不考虑样本权重。与min_samples_leaf及其加权cousin min_weight_fraction_leaf source )。

您的示例建议一个简单的实验检查:

from sklearn.tree import DecisionTreeClassifier
import numpy as np

X = np.array([1, 2, 3]).reshape(-1, 1)
y = [0, 0, 1]

tree = DecisionTreeClassifier()
tree.fit(X, y)
print(len(tree.tree_.feature))  # number of nodes
# 3

tree.set_params(min_samples_split=10)
tree.fit(X, y)
print(len(tree.tree_.feature))
# 1

tree.set_params(min_samples_split=10)
tree.fit(X, y, sample_weight=[20, 20, 20])
print(len(tree.tree_.feature))
# 1; the sample weights don't count to make 
#    each sample "large" enough for min_samples_split

No, see the source; min_samples_split does not take into consideration sample weights. Compare to min_samples_leaf and its weighted cousin min_weight_fraction_leaf (source).

Your example suggests an easy experiment to check:

from sklearn.tree import DecisionTreeClassifier
import numpy as np

X = np.array([1, 2, 3]).reshape(-1, 1)
y = [0, 0, 1]

tree = DecisionTreeClassifier()
tree.fit(X, y)
print(len(tree.tree_.feature))  # number of nodes
# 3

tree.set_params(min_samples_split=10)
tree.fit(X, y)
print(len(tree.tree_.feature))
# 1

tree.set_params(min_samples_split=10)
tree.fit(X, y, sample_weight=[20, 20, 20])
print(len(tree.tree_.feature))
# 1; the sample weights don't count to make 
#    each sample "large" enough for min_samples_split

sample_weight和min_samples_split在决策树中的相互作用

花间憩 2025-02-06 15:18:25

我一直在看您的代码片段。您的正确选项不会扩展。看起来可能是这样,因为您当前的HTML/CSS正在扩展父容器。如果您需要2列,则需要在HTML/CSS中这样做:

<html>
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.tailwindcss.com"></script>
    <script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
    
    <style>
      .md-w-48\/100 {
        width: 48%;
      }
    </style>
  </head>
  <body>
    <div class="flex flex-row flex-wrap w-full">
      <div class="flex flex-row flex-wrap w-full mt-8 px-6 xl:px-0">
        <h2 class="text-4xl font-mont font-bold md:text-left text-center">Casino & Gambling FAQs</h2>
      </div>
      <div class="max-w-7xl mt-8 px-6 xl:px-0 w-1/2 inline-block">
        <div class="flex flex-col flex-wrap justify-between w-full">
          <div class="flex flex-wrap flex-row justify-between mt-8 w-full">
            <div x-init="" x-data="{expanded: false}" :class="expanded ? 'h-full' : 'h-12'" class="w-full flex flex-wrap flex-col h-12">
              <div @click="expanded = !expanded" class="flex items-center px-10 py-4 border-b bg-white rounded-lg cursor-pointer">
                <div class="font-bold font-lato text-xsm bg-white">question</div>
                <div class="ml-auto p-2">
                  <svg width="8" height="6" viewBox="0 0 8 6" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M7.77083 0.937549C7.68535 0.850049 7.57545 0.812549 7.46555 0.812549C7.35565 0.812549 7.23354 0.862549 7.16027 0.937549L4.03424 4.11255L0.932622 0.937549C0.847145 0.850049 0.725034 0.800049 0.615134 0.800049C0.505234 0.800049 0.383123 0.850049 0.309857 0.925049C0.138902 1.10005 0.138902 1.38755 0.309857 1.56255L3.71675 5.06255C3.8877 5.23755 4.16856 5.23755 4.33951 5.06255L7.75862 1.57505C7.94178 1.40005 7.94178 1.11255 7.77083 0.937549Z" fill="#080F33">
                    </path>
                  </svg>
                </div>
              </div>
              <div x-show="expanded" class="px-10 py-4 text-left font-lato bg-gray-50 text-gray-500 flex-1" style="display: none;">
                'just a bunch of text'
              </div>    
            </div>
          </div>
          <div class="flex flex-wrap flex-row justify-between mt-8 w-full">
            <div x-init="" x-data="{expanded: false}" :class="expanded ? 'h-full' : 'h-12'" class="w-full flex flex-wrap flex-col h-12">
              <div @click="expanded = !expanded" class="flex items-center px-10 py-4 border-b bg-white rounded-lg cursor-pointer">
                <div class="font-bold font-lato text-xsm bg-white">question</div>
                <div class="ml-auto p-2">
                  <svg width="8" height="6" viewBox="0 0 8 6" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M7.77083 0.937549C7.68535 0.850049 7.57545 0.812549 7.46555 0.812549C7.35565 0.812549 7.23354 0.862549 7.16027 0.937549L4.03424 4.11255L0.932622 0.937549C0.847145 0.850049 0.725034 0.800049 0.615134 0.800049C0.505234 0.800049 0.383123 0.850049 0.309857 0.925049C0.138902 1.10005 0.138902 1.38755 0.309857 1.56255L3.71675 5.06255C3.8877 5.23755 4.16856 5.23755 4.33951 5.06255L7.75862 1.57505C7.94178 1.40005 7.94178 1.11255 7.77083 0.937549Z" fill="#080F33">
                    </path>
                  </svg>
                </div>
              </div>
              <div x-show="expanded" class="px-10 py-4 text-left font-lato bg-gray-50 text-gray-500 flex-1" style="display: none;">
                'just a bunch of text'
              </div>    
            </div>
          </div>
        </div>
      </div>
      <div class="max-w-7xl mt-8 px-6 xl:px-0 w-1/2 inline-block">
        <div class="flex flex-col flex-wrap justify-between w-full">
          <div class="flex flex-wrap flex-row justify-between mt-8 w-full">
            <div x-init="" x-data="{expanded: false}" :class="expanded ? 'h-full' : 'h-12'" class="w-full flex flex-wrap flex-col h-12">
              <div @click="expanded = !expanded" class="flex items-center px-10 py-4 border-b bg-white rounded-lg cursor-pointer">
                <div class="font-bold font-lato text-xsm bg-white">question</div>
                <div class="ml-auto p-2">
                  <svg width="8" height="6" viewBox="0 0 8 6" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M7.77083 0.937549C7.68535 0.850049 7.57545 0.812549 7.46555 0.812549C7.35565 0.812549 7.23354 0.862549 7.16027 0.937549L4.03424 4.11255L0.932622 0.937549C0.847145 0.850049 0.725034 0.800049 0.615134 0.800049C0.505234 0.800049 0.383123 0.850049 0.309857 0.925049C0.138902 1.10005 0.138902 1.38755 0.309857 1.56255L3.71675 5.06255C3.8877 5.23755 4.16856 5.23755 4.33951 5.06255L7.75862 1.57505C7.94178 1.40005 7.94178 1.11255 7.77083 0.937549Z" fill="#080F33">
                    </path>
                  </svg>
                </div>
              </div>
              <div x-show="expanded" class="px-10 py-4 text-left font-lato bg-gray-50 text-gray-500 flex-1" style="display: none;">
                'just a bunch of text'
              </div>    
            </div>
          </div>
          <div class="flex flex-wrap flex-row justify-between mt-8 w-full">
            <div x-init="" x-data="{expanded: false}" :class="expanded ? 'h-full' : 'h-12'" class="w-full flex flex-wrap flex-col h-12">
              <div @click="expanded = !expanded" class="flex items-center px-10 py-4 border-b bg-white rounded-lg cursor-pointer">
                <div class="font-bold font-lato text-xsm bg-white">question</div>
                <div class="ml-auto p-2">
                  <svg width="8" height="6" viewBox="0 0 8 6" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M7.77083 0.937549C7.68535 0.850049 7.57545 0.812549 7.46555 0.812549C7.35565 0.812549 7.23354 0.862549 7.16027 0.937549L4.03424 4.11255L0.932622 0.937549C0.847145 0.850049 0.725034 0.800049 0.615134 0.800049C0.505234 0.800049 0.383123 0.850049 0.309857 0.925049C0.138902 1.10005 0.138902 1.38755 0.309857 1.56255L3.71675 5.06255C3.8877 5.23755 4.16856 5.23755 4.33951 5.06255L7.75862 1.57505C7.94178 1.40005 7.94178 1.11255 7.77083 0.937549Z" fill="#080F33">
                    </path>
                  </svg>
                </div>
              </div>
              <div x-show="expanded" class="px-10 py-4 text-left font-lato bg-gray-50 text-gray-500 flex-1" style="display: none;">
                'just a bunch of text'
              </div>    
            </div>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>

如您所见,我已经将您的列分为2个不同的inline-block元素。这样,就不被视为一个父母,而扩大孩子不会在另一侧扩展容器。

I've been looking at your code snippet. Your right option isn't expanding. It may look like it is, because your current HTML/CSS is expanding the parent container. If you want 2 separate columns, you will need to make it as such in your HTML/CSS:

<html>
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.tailwindcss.com"></script>
    <script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
    
    <style>
      .md-w-48\/100 {
        width: 48%;
      }
    </style>
  </head>
  <body>
    <div class="flex flex-row flex-wrap w-full">
      <div class="flex flex-row flex-wrap w-full mt-8 px-6 xl:px-0">
        <h2 class="text-4xl font-mont font-bold md:text-left text-center">Casino & Gambling FAQs</h2>
      </div>
      <div class="max-w-7xl mt-8 px-6 xl:px-0 w-1/2 inline-block">
        <div class="flex flex-col flex-wrap justify-between w-full">
          <div class="flex flex-wrap flex-row justify-between mt-8 w-full">
            <div x-init="" x-data="{expanded: false}" :class="expanded ? 'h-full' : 'h-12'" class="w-full flex flex-wrap flex-col h-12">
              <div @click="expanded = !expanded" class="flex items-center px-10 py-4 border-b bg-white rounded-lg cursor-pointer">
                <div class="font-bold font-lato text-xsm bg-white">question</div>
                <div class="ml-auto p-2">
                  <svg width="8" height="6" viewBox="0 0 8 6" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M7.77083 0.937549C7.68535 0.850049 7.57545 0.812549 7.46555 0.812549C7.35565 0.812549 7.23354 0.862549 7.16027 0.937549L4.03424 4.11255L0.932622 0.937549C0.847145 0.850049 0.725034 0.800049 0.615134 0.800049C0.505234 0.800049 0.383123 0.850049 0.309857 0.925049C0.138902 1.10005 0.138902 1.38755 0.309857 1.56255L3.71675 5.06255C3.8877 5.23755 4.16856 5.23755 4.33951 5.06255L7.75862 1.57505C7.94178 1.40005 7.94178 1.11255 7.77083 0.937549Z" fill="#080F33">
                    </path>
                  </svg>
                </div>
              </div>
              <div x-show="expanded" class="px-10 py-4 text-left font-lato bg-gray-50 text-gray-500 flex-1" style="display: none;">
                'just a bunch of text'
              </div>    
            </div>
          </div>
          <div class="flex flex-wrap flex-row justify-between mt-8 w-full">
            <div x-init="" x-data="{expanded: false}" :class="expanded ? 'h-full' : 'h-12'" class="w-full flex flex-wrap flex-col h-12">
              <div @click="expanded = !expanded" class="flex items-center px-10 py-4 border-b bg-white rounded-lg cursor-pointer">
                <div class="font-bold font-lato text-xsm bg-white">question</div>
                <div class="ml-auto p-2">
                  <svg width="8" height="6" viewBox="0 0 8 6" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M7.77083 0.937549C7.68535 0.850049 7.57545 0.812549 7.46555 0.812549C7.35565 0.812549 7.23354 0.862549 7.16027 0.937549L4.03424 4.11255L0.932622 0.937549C0.847145 0.850049 0.725034 0.800049 0.615134 0.800049C0.505234 0.800049 0.383123 0.850049 0.309857 0.925049C0.138902 1.10005 0.138902 1.38755 0.309857 1.56255L3.71675 5.06255C3.8877 5.23755 4.16856 5.23755 4.33951 5.06255L7.75862 1.57505C7.94178 1.40005 7.94178 1.11255 7.77083 0.937549Z" fill="#080F33">
                    </path>
                  </svg>
                </div>
              </div>
              <div x-show="expanded" class="px-10 py-4 text-left font-lato bg-gray-50 text-gray-500 flex-1" style="display: none;">
                'just a bunch of text'
              </div>    
            </div>
          </div>
        </div>
      </div>
      <div class="max-w-7xl mt-8 px-6 xl:px-0 w-1/2 inline-block">
        <div class="flex flex-col flex-wrap justify-between w-full">
          <div class="flex flex-wrap flex-row justify-between mt-8 w-full">
            <div x-init="" x-data="{expanded: false}" :class="expanded ? 'h-full' : 'h-12'" class="w-full flex flex-wrap flex-col h-12">
              <div @click="expanded = !expanded" class="flex items-center px-10 py-4 border-b bg-white rounded-lg cursor-pointer">
                <div class="font-bold font-lato text-xsm bg-white">question</div>
                <div class="ml-auto p-2">
                  <svg width="8" height="6" viewBox="0 0 8 6" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M7.77083 0.937549C7.68535 0.850049 7.57545 0.812549 7.46555 0.812549C7.35565 0.812549 7.23354 0.862549 7.16027 0.937549L4.03424 4.11255L0.932622 0.937549C0.847145 0.850049 0.725034 0.800049 0.615134 0.800049C0.505234 0.800049 0.383123 0.850049 0.309857 0.925049C0.138902 1.10005 0.138902 1.38755 0.309857 1.56255L3.71675 5.06255C3.8877 5.23755 4.16856 5.23755 4.33951 5.06255L7.75862 1.57505C7.94178 1.40005 7.94178 1.11255 7.77083 0.937549Z" fill="#080F33">
                    </path>
                  </svg>
                </div>
              </div>
              <div x-show="expanded" class="px-10 py-4 text-left font-lato bg-gray-50 text-gray-500 flex-1" style="display: none;">
                'just a bunch of text'
              </div>    
            </div>
          </div>
          <div class="flex flex-wrap flex-row justify-between mt-8 w-full">
            <div x-init="" x-data="{expanded: false}" :class="expanded ? 'h-full' : 'h-12'" class="w-full flex flex-wrap flex-col h-12">
              <div @click="expanded = !expanded" class="flex items-center px-10 py-4 border-b bg-white rounded-lg cursor-pointer">
                <div class="font-bold font-lato text-xsm bg-white">question</div>
                <div class="ml-auto p-2">
                  <svg width="8" height="6" viewBox="0 0 8 6" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M7.77083 0.937549C7.68535 0.850049 7.57545 0.812549 7.46555 0.812549C7.35565 0.812549 7.23354 0.862549 7.16027 0.937549L4.03424 4.11255L0.932622 0.937549C0.847145 0.850049 0.725034 0.800049 0.615134 0.800049C0.505234 0.800049 0.383123 0.850049 0.309857 0.925049C0.138902 1.10005 0.138902 1.38755 0.309857 1.56255L3.71675 5.06255C3.8877 5.23755 4.16856 5.23755 4.33951 5.06255L7.75862 1.57505C7.94178 1.40005 7.94178 1.11255 7.77083 0.937549Z" fill="#080F33">
                    </path>
                  </svg>
                </div>
              </div>
              <div x-show="expanded" class="px-10 py-4 text-left font-lato bg-gray-50 text-gray-500 flex-1" style="display: none;">
                'just a bunch of text'
              </div>    
            </div>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>

As you can see, I've split your columns in to 2 different inline-block elements. This way, it is not seen as one parent, and expanding a child won't expand the container on the other side.

当单击一单击时,同一行的两个Divs扩展了两个尾风CSS Django Alpine JS

花间憩 2025-02-06 12:28:41

添加onclick = {(e)=&gt; e.stoppropagation()} in &lt; form.check&gt; ...&lt;/form.check>
e.stoppropagation()在标签中将有助于此标签阻止父母的onClick事件。

这里的代码: htttps:// codesandbox。 io/s/s/platvown-with-checkbox-forked-88H9m6?file =/src/app.js

import "./styles.scss";
import "bootstrap/dist/css/bootstrap.min.css";
import { Dropdown, Form } from "react-bootstrap";
export default function App() {
  return (
    <div className="App">
      <Dropdown className="dropdown-groove">
        <Dropdown.Toggle variant="outline-secondary " id="dropdown-basic">
          Select...
          <label className="dropdown-label">Dropdown label</label>
        </Dropdown.Toggle>

        <Dropdown.Menu>
          <Dropdown.Item href="#/action-1">
            {" "}
            <Form.Check
              onClick={(e) => e.stopPropagation()} //<=== Add here
              className="checkbox-groove"
              inline
              label="Unselected"
              name="group1"
              type="checkbox"
            />{" "}
          </Dropdown.Item>
          <Dropdown.Item href="#/action-2">List Item 2</Dropdown.Item>
          <Dropdown.Item href="#/action-3">List Item 3</Dropdown.Item>
          <Dropdown.Item href="#/action-4">List Item 4</Dropdown.Item>
          <Dropdown.Item href="#/action-5">List Item 5</Dropdown.Item>
        </Dropdown.Menu>
      </Dropdown>
    </div>
  );
}

Add onClick={(e) => e.stopPropagation()} in <Form.Check>...</Form.Check>.
e.stopPropagation() in tag will help this tag prevent onClick event from parent.

Code here: https://codesandbox.io/s/dropdown-with-checkbox-forked-88h9m6?file=/src/App.js

import "./styles.scss";
import "bootstrap/dist/css/bootstrap.min.css";
import { Dropdown, Form } from "react-bootstrap";
export default function App() {
  return (
    <div className="App">
      <Dropdown className="dropdown-groove">
        <Dropdown.Toggle variant="outline-secondary " id="dropdown-basic">
          Select...
          <label className="dropdown-label">Dropdown label</label>
        </Dropdown.Toggle>

        <Dropdown.Menu>
          <Dropdown.Item href="#/action-1">
            {" "}
            <Form.Check
              onClick={(e) => e.stopPropagation()} //<=== Add here
              className="checkbox-groove"
              inline
              label="Unselected"
              name="group1"
              type="checkbox"
            />{" "}
          </Dropdown.Item>
          <Dropdown.Item href="#/action-2">List Item 2</Dropdown.Item>
          <Dropdown.Item href="#/action-3">List Item 3</Dropdown.Item>
          <Dropdown.Item href="#/action-4">List Item 4</Dropdown.Item>
          <Dropdown.Item href="#/action-5">List Item 5</Dropdown.Item>
        </Dropdown.Menu>
      </Dropdown>
    </div>
  );
}

如何在下拉列表项中单击复选框时避免添加下拉菜单隐藏?

花间憩 2025-02-06 05:47:52
import 'dart:convert';

const raw = 
'''
  [{"color":"#000000","quantity":"100","price":"999","attribute":{"id":1,"name":"Iphone 12"}},{"color":"#cd7d96","quantity":"40","price":"555","attribute":{"id":2,"name":"SAMSUNG"}},{"color":"#66cccc","quantity":"500","price":"1000","attribute":{"id":1,"name":"OPPO"}}]
''';

typedef JMap = Map<String, dynamic>;
typedef LJMap = List<JMap>;

void groupById() {
  final data = (jsonDecode(raw) as List).cast<JMap>();
  var result = <JMap>[];
  data.map<int>((m) => m['attribute']['id']).toSet().forEach((e) { 
    result.add({
      'attribute_id': e, 
      'values': data.where((m) => m['attribute']['id'] == e).map((m) => m['color']).toList(),
    });
  });

  print(result);
}

void main(List<String> args) {
  groupById();
}

输出:

[{attribute_id: 1, values: [#000000, #66cccc]}, {attribute_id: 2, values: [#cd7d96]}]
import 'dart:convert';

const raw = 
'''
  [{"color":"#000000","quantity":"100","price":"999","attribute":{"id":1,"name":"Iphone 12"}},{"color":"#cd7d96","quantity":"40","price":"555","attribute":{"id":2,"name":"SAMSUNG"}},{"color":"#66cccc","quantity":"500","price":"1000","attribute":{"id":1,"name":"OPPO"}}]
''';

typedef JMap = Map<String, dynamic>;
typedef LJMap = List<JMap>;

void groupById() {
  final data = (jsonDecode(raw) as List).cast<JMap>();
  var result = <JMap>[];
  data.map<int>((m) => m['attribute']['id']).toSet().forEach((e) { 
    result.add({
      'attribute_id': e, 
      'values': data.where((m) => m['attribute']['id'] == e).map((m) => m['color']).toList(),
    });
  });

  print(result);
}

void main(List<String> args) {
  groupById();
}

Output:

[{attribute_id: 1, values: [#000000, #66cccc]}, {attribute_id: 2, values: [#cd7d96]}]

颤音:iD的JSON字符串的数组列表组。

花间憩 2025-02-05 10:39:44

使用您的Dropbox数据:

library(terra)
ndwi <- rast('Clip_ndwi_poslije1.tif')
ndwi_vec <- values(ndwi, mat = FALSE)
> length(which(ndwi_vec > 0))
[1] 21157
> length(which(ndwi_vec <= 0))
[1] 13217
> dim(ndwi)[1]
[1] 220
> dim(ndwi)[1]*dim(ndwi)[2]
[1] 58300
> sum(length(which(ndwi_vec > 0)), length(which(ndwi_vec <= 0)))
[1] 34374
> table(is.na(ndwi[])) #  see below

FALSE  TRUE 
34374 23926 

表方法来自 sof-gis?s ,让您开始。

Using your dropbox data:

library(terra)
ndwi <- rast('Clip_ndwi_poslije1.tif')
ndwi_vec <- values(ndwi, mat = FALSE)
> length(which(ndwi_vec > 0))
[1] 21157
> length(which(ndwi_vec <= 0))
[1] 13217
> dim(ndwi)[1]
[1] 220
> dim(ndwi)[1]*dim(ndwi)[2]
[1] 58300
> sum(length(which(ndwi_vec > 0)), length(which(ndwi_vec <= 0)))
[1] 34374
> table(is.na(ndwi[])) #  see below

FALSE  TRUE 
34374 23926 

Table approach is from SOF-GIS ?s, and get you started.

在r中计数相同值的像素

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文