茶花眉

文章 评论 浏览 29

茶花眉 2025-02-20 20:01:34
createDelegated(EMAIL_ADDRESS_CREATED_WHEN_CREATING_THE_SERVICE_ACCOUNT)

您应该将其设置的电子邮件是您已配置委托的工作空间帐户上用户的电子邮件。

createDelegated("[email protected]")

发送的发送也应从您的域上的用户发送。服务的方式对您进行预先配置的方式来处理他们在域上模仿用户。这样,服务帐户假装是该用户。

如果您尚未阅读此信息:我强烈建议这样做。

createDelegated(EMAIL_ADDRESS_CREATED_WHEN_CREATING_THE_SERVICE_ACCOUNT)

The email you should be setting this to is the email of the user on your workspace account that you have configured delegation for.

createDelegated("[email protected]")

Send should also be sent from the user on your domain. The way service accounts you preconfigure them to work impersonate a user on your domain. In this way the service account is pretending to be that user.

If you have not already read this: Perform Google Workspace Domain-Wide Delegation of Authority I can highly recommend doing so.

通过Google API发送电子邮件 - 前提条件失败

茶花眉 2025-02-20 12:04:53
<form action="/waifus/{{ $waifu->id }}" method="POST">
@csrf
@method('DELETE')
<button type="submit" class="text-red-500"> Delete</button>
</form>

//Delete
public function delete($waifu)
{   
  Model::find($waifu)->delete(); // Model name will be your Model name
  return redirect('/')->with('message', 'Waifu deleted succesfully');
}
<form action="/waifus/{{ $waifu->id }}" method="POST">
@csrf
@method('DELETE')
<button type="submit" class="text-red-500"> Delete</button>
</form>

//Delete
public function delete($waifu)
{   
  Model::find($waifu)->delete(); // Model name will be your Model name
  return redirect('/')->with('message', 'Waifu deleted succesfully');
}

从数据库laravel9中删除

茶花眉 2025-02-20 07:04:12

我想知道您为什么问这个,但是无论如何,这都是一个有趣的练习。这是我的实现:

library('dplyr')


# define cars -------------------------------------------------------------

original_cars <- c("self", "funny", "nymph")
new_cars <- c("house", "garden", "duck", "evil", "fluff")
cars <- c(original_cars, new_cars)


# get all possible connections ('parts') per car --------------------------

car_parts <- lapply(seq_along(cars), \(car_id) {
  
  car = cars[car_id]
  n = nchar(car)
  
  ids <- rep(car_id, n)
  names <- rep(car, n)
  left <- vapply(seq_len(n), \(i) substr(car, 1, i), "")
  right <- vapply(seq_len(n), \(i) substr(car, n-i+1, n), "")
  overlap <- nchar(left)
  
  data.frame(car.id = ids, car.name = names, left = left, right = right, overlap = overlap)
  
}) |> do.call(rbind, args=_)

# > car_parts
#    car.id car.name   left  right overlap
# 1       1     self      s      f       1
# 2       1     self     se     lf       2
# 3       1     self    sel    elf       3
# 4       1     self   self   self       4
# 5       2    funny      f      y       1
# 6       2    funny     fu     ny       2
# 7       2    funny    fun    nny       3
# 8       2    funny   funn   unny       4
# 9       2    funny  funny  funny       5
# 10      3    nymph      n      h       1
# [...]


# get all possible connections between two cars ---------------------------

connections <- inner_join(car_parts |> select(-left),
           car_parts |> select(-right),
           by = c('overlap', 'right' = 'left'),
           suffix = c('.left', '.right')) |>
  filter(car.id.left != car.id.right) |>
  mutate(connection.id = row_number()) |>
  select(connection.id, car.id.left, car.id.right, car.name.left, car.name.right, coupling = right)

rm(car_parts)

# > connections
#   connection.id car.id.left car.id.right car.name.left car.name.right coupling
# 1             1           1            2          self          funny        f
# 2             2           1            8          self          fluff        f
# 3             3           2            3         funny          nymph       ny
# 4             4           3            4         nymph          house        h
# 5             5           4            7         house           evil        e
# 6             6           4            1         house           self       se
# 7             7           5            3        garden          nymph        n
# 8             8           8            2         fluff          funny        f


# function to store valid trains ------------------------------------------

# example:
# valid_trains <- list()
# valid_trains <- add_valid_train( valid_trains, c(1, 8), c(2) )

add_valid_train <- function(valid_trains, train_cars, train_connections) {
  
  names = c(cars[train_cars[1]],
            vapply(train_connections, \(x) connections$car.name.right[x], "") )
  
  couplings = vapply(train_connections, \(x) connections$coupling[x], "")
  
  append(valid_trains, list(list(cars = train_cars, names = names, couplings = couplings)))
  
}


# function to recursively find next cars to add to train ------------------

# example:
# add_car(9, 5, c(1,2,3), c(1,3,5))

add_car <- function(valid_trains, new_car, new_connection = NULL, train_cars = c(), train_connections = c(), depth = 0) {
  
  cat(strrep('   ',depth), cars[new_car],'\n', sep='')
  
  # store current train as valid
  train_cars <- c(train_cars, new_car)
  train_connections <- c(train_connections, new_connection)
  
  # find next possible cars to add; save train if no more options, otherwise add all options
  options <- connections |> filter(car.id.left == new_car, ! car.id.right %in% train_cars)
  if(nrow(options) == 0) valid_trains <- add_valid_train(valid_trains, train_cars, train_connections) # save only the longest options
  for(i in seq_len(nrow(options))) valid_trains <- add_car(valid_trains, options$car.id.right[i], options$connection.id[i], train_cars, train_connections, depth+1)
  
  return(valid_trains)
  
}


# get all valid trains ----------------------------------------------------

valid_trains <- list()
for(i in seq_along(cars)) add_car(valid_trains, i) -> valid_trains

# filter valid trains that have all cars from `original_cars` -------------

mask <- vapply(valid_trains, \(x) all(seq_along(original_cars) %in% x$cars), T)

new_trains <- lapply(valid_trains[mask], \(x) {
  x$newcars <- setdiff(x$cars, seq_along(original_cars))
  x$newnames <- cars[x$newcars]
  x
})

# print names of all trains that contain all 'original' cars:
#
# > sapply(new_trains, \(x) x$names)
# [[1]] "self"  "funny" "nymph" "house" "evil" 
# [[2]] "self"  "fluff" "funny" "nymph" "house" "evil" 
# [[3]] "funny" "nymph" "house" "self"  "fluff"
# [[4]] "nymph" "house" "self"  "funny"
# [[5]] "nymph" "house" "self"  "fluff" "funny"
# [[6]] "house" "self"  "funny" "nymph"
# [[7]] "house" "self"  "fluff" "funny" "nymph"
# [[8]] "garden" "nymph"  "house"  "self"   "funny" 
# [[9]] "garden" "nymph"  "house"  "self"   "fluff"  "funny" 
# [[10]] "fluff" "funny" "nymph" "house" "self" 

## All possible trains are in `valid_trains`, all of those where *all* the original cars are used are in `new_trains`.
## 
## It is possible that some trains are subsets of others.

编辑:当我查看您自己的实施时,我认为您对最长的火车感兴趣。现在,您解释了目的,我调整了算法以采用原始汽车,然后查看可以将哪些新车单独添加到原始组合中。有了以前的代码,一长串潜在的新名称将创建一些巨大的火车,这些火车对于命名家庭而言是非常不可行的。

library('dplyr')


# define cars -------------------------------------------------------------

original_cars <- c("self", "funny", "nymph")
new_cars <- c("house", "garden", "duck", "evil", "fluff")


# function to get all possible connections between a set of cars ----------

# example:
# cars <- c("self", "funny", "nymph", "house")
# get_connections(cars)
#
# > get_connections(c("self", "funny", "nymph", "house"))
#   connection.id car.id.left car.id.right car.name.left car.name.right coupling
# 1             1           1            2          self          funny        f
# 2             2           2            3         funny          nymph       ny
# 3             3           3            4         nymph          house        h
# 4             4           4            1         house           self       se

get_connections <- function(cars) {
  
  # get all connections the cars can make
  car_parts <- lapply(seq_along(cars), \(car_id) {
    
    car = cars[car_id]
    n = nchar(car)
    
    ids <- rep(car_id, n)
    names <- rep(car, n)
    left <- vapply(seq_len(n), \(i) substr(car, 1, i), "")
    right <- vapply(seq_len(n), \(i) substr(car, n-i+1, n), "")
    overlap <- nchar(left)
    
    data.frame(car.id = ids, car.name = names, left = left, right = right, overlap = overlap)
    
  }) |> do.call(rbind, args=_)
  
  # > car_parts
  #    car.id car.name   left  right overlap
  # 1       1     self      s      f       1
  # 2       1     self     se     lf       2
  # 3       1     self    sel    elf       3
  # 4       1     self   self   self       4
  # 5       2    funny      f      y       1
  # 6       2    funny     fu     ny       2
  # [...]
  
  # return all possible connections between two cars
  
  inner_join(car_parts |> select(-left),
                            car_parts |> select(-right),
                            by = c('overlap', 'right' = 'left'),
                            suffix = c('.left', '.right')) |>
    filter(car.id.left != car.id.right) |>
    mutate(connection.id = row_number()) |>
    select(connection.id, car.id.left, car.id.right, car.name.left, car.name.right, coupling = right)
  
}


# function to store valid trains ------------------------------------------

# example:
# cars <- c("self", "funny", "nymph", "house")
# connections <- get_connections(cars)
# valid_trains <- list()
# valid_trains <- add_valid_train( cars, connections, valid_trains, c(2, 3), c(2) )

add_valid_train <- function(cars, connections, valid_trains, train_cars, train_connections) {
  
  names = c(cars[train_cars[1]],
            vapply(train_connections, \(x) connections$car.name.right[x], "") )
  
  couplings = vapply(train_connections, \(x) connections$coupling[x], "")
  
  append(valid_trains, list(list(cars = train_cars, names = names, couplings = couplings)))
  
}


# function to recursively find next cars to add to train ------------------

# example:
# cars <- c("self", "funny", "nymph", "house")
# connections <- get_connections(cars)
# valid_trains <- list()
# add_car(cars, connections, valid_trains, 2)

add_car <- function(cars, connections, valid_trains, new_car, new_connection = NULL, train_cars = c(), train_connections = c(), depth = 0) {
  
  cat(strrep('   ',depth), cars[new_car], '\n', sep='')
  
  # store current train as valid
  train_cars <- c(train_cars, new_car)
  train_connections <- c(train_connections, new_connection)
  
  # find next possible cars to add
  options <- connections |> filter(car.id.left == new_car, ! car.id.right %in% train_cars)
  for(i in seq_len(nrow(options))) valid_trains <- add_car(cars, connections, valid_trains, options$car.id.right[i], options$connection.id[i], train_cars, train_connections, depth+1)
  
  # save train if no more options
  if(nrow(options) == 0) valid_trains <- add_valid_train(cars, connections, valid_trains, train_cars, train_connections)
  
  return(valid_trains)
  
}


# find individual new cars that can be added to existing cars --------------

results <- lapply(new_cars, function(new_car) {
  
  cat('adding "',new_car,'":\n', sep='')
  cars <- c(original_cars, new_car)
  connections <- get_connections(cars)
  
  # get all possible trains
  valid_trains <- list()
  for(i in seq_along(cars)) add_car(cars, connections, valid_trains, i) -> valid_trains
  
  cat('\n')
  
  # return only trains where all cars are used
  valid_trains <- valid_trains[ sapply(valid_trains, \(x) length(x$cars)) == length(cars) ]
  return(list(new_car = new_car, options = length(valid_trains), trains = valid_trains))
})

for(result in results) {
  cat('\n', result$new_car, ': ', result$options, ' options ', sep='')
  for(train in result$trains) {
    cat('[',train$names,'] ')
  }
}
# detailed results are in `results`
house: 4 options [ self funny nymph house ] [ funny nymph house self ] [ nymph house self funny ] [ house self funny nymph ] 
garden: 0 options 
duck: 0 options 
evil: 0 options 
fluff: 1 options [ self fluff funny nymph ] 

I'm wondering why you asked this, but it was a fun exercise regardless. Here's my implementation:

library('dplyr')


# define cars -------------------------------------------------------------

original_cars <- c("self", "funny", "nymph")
new_cars <- c("house", "garden", "duck", "evil", "fluff")
cars <- c(original_cars, new_cars)


# get all possible connections ('parts') per car --------------------------

car_parts <- lapply(seq_along(cars), \(car_id) {
  
  car = cars[car_id]
  n = nchar(car)
  
  ids <- rep(car_id, n)
  names <- rep(car, n)
  left <- vapply(seq_len(n), \(i) substr(car, 1, i), "")
  right <- vapply(seq_len(n), \(i) substr(car, n-i+1, n), "")
  overlap <- nchar(left)
  
  data.frame(car.id = ids, car.name = names, left = left, right = right, overlap = overlap)
  
}) |> do.call(rbind, args=_)

# > car_parts
#    car.id car.name   left  right overlap
# 1       1     self      s      f       1
# 2       1     self     se     lf       2
# 3       1     self    sel    elf       3
# 4       1     self   self   self       4
# 5       2    funny      f      y       1
# 6       2    funny     fu     ny       2
# 7       2    funny    fun    nny       3
# 8       2    funny   funn   unny       4
# 9       2    funny  funny  funny       5
# 10      3    nymph      n      h       1
# [...]


# get all possible connections between two cars ---------------------------

connections <- inner_join(car_parts |> select(-left),
           car_parts |> select(-right),
           by = c('overlap', 'right' = 'left'),
           suffix = c('.left', '.right')) |>
  filter(car.id.left != car.id.right) |>
  mutate(connection.id = row_number()) |>
  select(connection.id, car.id.left, car.id.right, car.name.left, car.name.right, coupling = right)

rm(car_parts)

# > connections
#   connection.id car.id.left car.id.right car.name.left car.name.right coupling
# 1             1           1            2          self          funny        f
# 2             2           1            8          self          fluff        f
# 3             3           2            3         funny          nymph       ny
# 4             4           3            4         nymph          house        h
# 5             5           4            7         house           evil        e
# 6             6           4            1         house           self       se
# 7             7           5            3        garden          nymph        n
# 8             8           8            2         fluff          funny        f


# function to store valid trains ------------------------------------------

# example:
# valid_trains <- list()
# valid_trains <- add_valid_train( valid_trains, c(1, 8), c(2) )

add_valid_train <- function(valid_trains, train_cars, train_connections) {
  
  names = c(cars[train_cars[1]],
            vapply(train_connections, \(x) connections$car.name.right[x], "") )
  
  couplings = vapply(train_connections, \(x) connections$coupling[x], "")
  
  append(valid_trains, list(list(cars = train_cars, names = names, couplings = couplings)))
  
}


# function to recursively find next cars to add to train ------------------

# example:
# add_car(9, 5, c(1,2,3), c(1,3,5))

add_car <- function(valid_trains, new_car, new_connection = NULL, train_cars = c(), train_connections = c(), depth = 0) {
  
  cat(strrep('   ',depth), cars[new_car],'\n', sep='')
  
  # store current train as valid
  train_cars <- c(train_cars, new_car)
  train_connections <- c(train_connections, new_connection)
  
  # find next possible cars to add; save train if no more options, otherwise add all options
  options <- connections |> filter(car.id.left == new_car, ! car.id.right %in% train_cars)
  if(nrow(options) == 0) valid_trains <- add_valid_train(valid_trains, train_cars, train_connections) # save only the longest options
  for(i in seq_len(nrow(options))) valid_trains <- add_car(valid_trains, options$car.id.right[i], options$connection.id[i], train_cars, train_connections, depth+1)
  
  return(valid_trains)
  
}


# get all valid trains ----------------------------------------------------

valid_trains <- list()
for(i in seq_along(cars)) add_car(valid_trains, i) -> valid_trains

# filter valid trains that have all cars from `original_cars` -------------

mask <- vapply(valid_trains, \(x) all(seq_along(original_cars) %in% x$cars), T)

new_trains <- lapply(valid_trains[mask], \(x) {
  x$newcars <- setdiff(x$cars, seq_along(original_cars))
  x$newnames <- cars[x$newcars]
  x
})

# print names of all trains that contain all 'original' cars:
#
# > sapply(new_trains, \(x) x$names)
# [[1]] "self"  "funny" "nymph" "house" "evil" 
# [[2]] "self"  "fluff" "funny" "nymph" "house" "evil" 
# [[3]] "funny" "nymph" "house" "self"  "fluff"
# [[4]] "nymph" "house" "self"  "funny"
# [[5]] "nymph" "house" "self"  "fluff" "funny"
# [[6]] "house" "self"  "funny" "nymph"
# [[7]] "house" "self"  "fluff" "funny" "nymph"
# [[8]] "garden" "nymph"  "house"  "self"   "funny" 
# [[9]] "garden" "nymph"  "house"  "self"   "fluff"  "funny" 
# [[10]] "fluff" "funny" "nymph" "house" "self" 

## All possible trains are in `valid_trains`, all of those where *all* the original cars are used are in `new_trains`.
## 
## It is possible that some trains are subsets of others.

edit: When I looked at your own implementation, I thought you were interested in the longest possible trains. Now you explained the purpose, I adapted the algorithm to take the original cars, and see which of the new cars could be added individually to the original set. With the previous code, a long list of potential new names would have created some huge trains that would be very unfeasible for naming a family.

library('dplyr')


# define cars -------------------------------------------------------------

original_cars <- c("self", "funny", "nymph")
new_cars <- c("house", "garden", "duck", "evil", "fluff")


# function to get all possible connections between a set of cars ----------

# example:
# cars <- c("self", "funny", "nymph", "house")
# get_connections(cars)
#
# > get_connections(c("self", "funny", "nymph", "house"))
#   connection.id car.id.left car.id.right car.name.left car.name.right coupling
# 1             1           1            2          self          funny        f
# 2             2           2            3         funny          nymph       ny
# 3             3           3            4         nymph          house        h
# 4             4           4            1         house           self       se

get_connections <- function(cars) {
  
  # get all connections the cars can make
  car_parts <- lapply(seq_along(cars), \(car_id) {
    
    car = cars[car_id]
    n = nchar(car)
    
    ids <- rep(car_id, n)
    names <- rep(car, n)
    left <- vapply(seq_len(n), \(i) substr(car, 1, i), "")
    right <- vapply(seq_len(n), \(i) substr(car, n-i+1, n), "")
    overlap <- nchar(left)
    
    data.frame(car.id = ids, car.name = names, left = left, right = right, overlap = overlap)
    
  }) |> do.call(rbind, args=_)
  
  # > car_parts
  #    car.id car.name   left  right overlap
  # 1       1     self      s      f       1
  # 2       1     self     se     lf       2
  # 3       1     self    sel    elf       3
  # 4       1     self   self   self       4
  # 5       2    funny      f      y       1
  # 6       2    funny     fu     ny       2
  # [...]
  
  # return all possible connections between two cars
  
  inner_join(car_parts |> select(-left),
                            car_parts |> select(-right),
                            by = c('overlap', 'right' = 'left'),
                            suffix = c('.left', '.right')) |>
    filter(car.id.left != car.id.right) |>
    mutate(connection.id = row_number()) |>
    select(connection.id, car.id.left, car.id.right, car.name.left, car.name.right, coupling = right)
  
}


# function to store valid trains ------------------------------------------

# example:
# cars <- c("self", "funny", "nymph", "house")
# connections <- get_connections(cars)
# valid_trains <- list()
# valid_trains <- add_valid_train( cars, connections, valid_trains, c(2, 3), c(2) )

add_valid_train <- function(cars, connections, valid_trains, train_cars, train_connections) {
  
  names = c(cars[train_cars[1]],
            vapply(train_connections, \(x) connections$car.name.right[x], "") )
  
  couplings = vapply(train_connections, \(x) connections$coupling[x], "")
  
  append(valid_trains, list(list(cars = train_cars, names = names, couplings = couplings)))
  
}


# function to recursively find next cars to add to train ------------------

# example:
# cars <- c("self", "funny", "nymph", "house")
# connections <- get_connections(cars)
# valid_trains <- list()
# add_car(cars, connections, valid_trains, 2)

add_car <- function(cars, connections, valid_trains, new_car, new_connection = NULL, train_cars = c(), train_connections = c(), depth = 0) {
  
  cat(strrep('   ',depth), cars[new_car], '\n', sep='')
  
  # store current train as valid
  train_cars <- c(train_cars, new_car)
  train_connections <- c(train_connections, new_connection)
  
  # find next possible cars to add
  options <- connections |> filter(car.id.left == new_car, ! car.id.right %in% train_cars)
  for(i in seq_len(nrow(options))) valid_trains <- add_car(cars, connections, valid_trains, options$car.id.right[i], options$connection.id[i], train_cars, train_connections, depth+1)
  
  # save train if no more options
  if(nrow(options) == 0) valid_trains <- add_valid_train(cars, connections, valid_trains, train_cars, train_connections)
  
  return(valid_trains)
  
}


# find individual new cars that can be added to existing cars --------------

results <- lapply(new_cars, function(new_car) {
  
  cat('adding "',new_car,'":\n', sep='')
  cars <- c(original_cars, new_car)
  connections <- get_connections(cars)
  
  # get all possible trains
  valid_trains <- list()
  for(i in seq_along(cars)) add_car(cars, connections, valid_trains, i) -> valid_trains
  
  cat('\n')
  
  # return only trains where all cars are used
  valid_trains <- valid_trains[ sapply(valid_trains, \(x) length(x$cars)) == length(cars) ]
  return(list(new_car = new_car, options = length(valid_trains), trains = valid_trains))
})

for(result in results) {
  cat('\n', result$new_car, ': ', result$options, ' options ', sep='')
  for(train in result$trains) {
    cat('[',train$names,'] ')
  }
}
# detailed results are in `results`
house: 4 options [ self funny nymph house ] [ funny nymph house self ] [ nymph house self funny ] [ house self funny nymph ] 
garden: 0 options 
duck: 0 options 
evil: 0 options 
fluff: 1 options [ self fluff funny nymph ] 

在单词中找到重叠的字母

茶花眉 2025-02-19 23:48:02

这将做我相信您的问题要问的:

keys = ['key1', 'key2', 'key3']
values = [-1.5, -.8]
from itertools import product
base_points = [{keys[i]:combo[i] for i in range(len(keys))} for combo in product(values, repeat=len(keys))]

输出:

[{'key1': -1.5, 'key2': -1.5, 'key3': -1.5},
 {'key1': -1.5, 'key2': -1.5, 'key3': -0.8},
 {'key1': -1.5, 'key2': -0.8, 'key3': -1.5},
 {'key1': -1.5, 'key2': -0.8, 'key3': -0.8},
 {'key1': -0.8, 'key2': -1.5, 'key3': -1.5},
 {'key1': -0.8, 'key2': -1.5, 'key3': -0.8},
 {'key1': -0.8, 'key2': -0.8, 'key3': -1.5},
 {'key1': -0.8, 'key2': -0.8, 'key3': -0.8}]

说明:

  • 变量 values 是任意长度
  • itertools.product() 提供嵌套的for-for-for-for-for-for-for-for-for-for-for-for-cartive 在每个关键位置中循环在为每个关键位置的每个可能的值组合创建

This will do what I believe your question is asking:

keys = ['key1', 'key2', 'key3']
values = [-1.5, -.8]
from itertools import product
base_points = [{keys[i]:combo[i] for i in range(len(keys))} for combo in product(values, repeat=len(keys))]

Output:

[{'key1': -1.5, 'key2': -1.5, 'key3': -1.5},
 {'key1': -1.5, 'key2': -1.5, 'key3': -0.8},
 {'key1': -1.5, 'key2': -0.8, 'key3': -1.5},
 {'key1': -1.5, 'key2': -0.8, 'key3': -0.8},
 {'key1': -0.8, 'key2': -1.5, 'key3': -1.5},
 {'key1': -0.8, 'key2': -1.5, 'key3': -0.8},
 {'key1': -0.8, 'key2': -0.8, 'key3': -1.5},
 {'key1': -0.8, 'key2': -0.8, 'key3': -0.8}]

Explanation:

  • The variables keys and values are lists of arbitrary length
  • itertools.product() provides nested for-loop behavior to cycle through the items in values at each key position so that a separate dictionary can be created for each possible combination of values at each key position

创建一个具有可变键和可变循环数量的词典

茶花眉 2025-02-19 21:54:38

因此,似乎内核在启用UART4时并没有真正悬挂。
由于某种原因,UART4被映射到TTYS0 - 打破了控制台输出。

设置:
Beaglebone黑色-Yocto Kirkstone-机器:Beaglebone -Yocto。

这是AM335X-BONE-COMMON.DTSI的相关部分:

uart0_pins: pinmux_uart0_pins {
    pinctrl-single,pins = <
        AM33XX_PADCONF(AM335X_PIN_UART0_RXD, PIN_INPUT_PULLUP, MUX_MODE0)   /* Debug Header - UART0_RX */
        AM33XX_PADCONF(AM335X_PIN_UART0_TXD, PIN_OUTPUT_PULLDOWN, MUX_MODE0)    /* Debug Header - UART0_TX */
    >;
};

uart1_pins: pinmux_uart1_pins {
    pinctrl-single,pins = <
        AM33XX_PADCONF(AM335X_PIN_UART1_RXD, PIN_INPUT_PULLUP, MUX_MODE0)   /* P9-26 UART1_RX */
        AM33XX_PADCONF(AM335X_PIN_UART1_TXD, PIN_OUTPUT_PULLDOWN, MUX_MODE0)    /* P9-24 UART1_TX */
    >;
};

uart2_pins: pinmux_uart2_pins {
    pinctrl-single,pins = <
        AM33XX_PADCONF(AM335X_PIN_SPI0_SCLK, PIN_INPUT_PULLUP, MUX_MODE1)   /* P9-22 UART2_RX */
        AM33XX_PADCONF(AM335X_PIN_SPI0_D0, PIN_OUTPUT_PULLDOWN, MUX_MODE1)      /* P9-21 UART2_TX */
    >;
};

uart4_pins: pinmux_uart4_pins {
    pinctrl-single,pins = <
        AM33XX_PADCONF(AM335X_PIN_GPMC_WAIT0, PIN_INPUT, MUX_MODE6)     /* P9-11 UART4_RX */    
        AM33XX_PADCONF(AM335X_PIN_GPMC_WPN, PIN_OUTPUT_PULLDOWN, MUX_MODE6) /* P9-13 UART4_TX */    
    >;
};

一旦董事会启动 - 我可以从以太网进入它。这是Pinctrl和Serial的输出:

root@beaglebone-yocto:~# cat /sys/kernel/debug/pinctrl/pinctrl-maps 
Pinctrl maps:
device 44e10800.pinmux
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_clkout2_pin
function pinmux_clkout2_pin

device 48022000.serial
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_uart1_pins
function pinmux_uart1_pins

device 48024000.serial
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_uart2_pins
function pinmux_uart2_pins

device 4819c000.i2c
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_i2c2_pins
function pinmux_i2c2_pins

device 481a8000.serial
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_uart4_pins
function pinmux_uart4_pins

device 4a100000.switch
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group cpsw_default
function cpsw_default

device 4a100000.switch
state sleep
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group cpsw_sleep
function cpsw_sleep

device 4a101000.mdio
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group davinci_mdio_default
function davinci_mdio_default

device 4a101000.mdio
state sleep
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group davinci_mdio_sleep
function davinci_mdio_sleep

device 44e09000.serial
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_uart0_pins
function pinmux_uart0_pins

device 44e0b000.i2c
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_i2c0_pins
function pinmux_i2c0_pins

device 48060000.mmc
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_mmc1_pins
function pinmux_mmc1_pins

device 481d8000.mmc
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_emmc_pins
function pinmux_emmc_pins

root@beaglebone-yocto:~# cat /proc/tty/driver/serial
serinfo:1.0 driver revision:
0: uart:8250 mmio:0x481A8000 irq:35 tx:871 rx:0 RTS|CTS|DTR|DSR
1: uart:8250 mmio:0x48022000 irq:24 tx:0 rx:0 CTS|DSR|CD|RI
2: uart:8250 mmio:0x48024000 irq:25 tx:0 rx:0 CTS|DSR
3: uart:8250 mmio:0x44E09000 irq:18 tx:0 rx:0 CTS|D

如您所见,UART4被映射到 /dev /ttys0,并且UART0在启动后映射到 /dev /ttys3。

我不确定为什么UART4映射到TTYS0而不是TTYS4。

我什至看不到 /dev /ttys4,尽管它是AM33xx.dtsi中的别名

root@beaglebone-yocto:~# ls -la /dev/ttyS*
crw--w---- 1 root tty     4, 64 Mar  9 12:45 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 Jan  1  2000 /dev/ttyS1
crw-rw---- 1 root dialout 4, 66 Jan  1  2000 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 Jan  1  2000 /dev/ttyS3

So, it would seem that the kernel doesn't really hang when enabling UART4.
For some reason, UART4 gets mapped to ttyS0 - which breaks the console output.

Setup:
Beaglebone Black - Yocto Kirkstone - Machine: beaglebone-yocto.

This is the relevant part from am335x-bone-common.dtsi:

uart0_pins: pinmux_uart0_pins {
    pinctrl-single,pins = <
        AM33XX_PADCONF(AM335X_PIN_UART0_RXD, PIN_INPUT_PULLUP, MUX_MODE0)   /* Debug Header - UART0_RX */
        AM33XX_PADCONF(AM335X_PIN_UART0_TXD, PIN_OUTPUT_PULLDOWN, MUX_MODE0)    /* Debug Header - UART0_TX */
    >;
};

uart1_pins: pinmux_uart1_pins {
    pinctrl-single,pins = <
        AM33XX_PADCONF(AM335X_PIN_UART1_RXD, PIN_INPUT_PULLUP, MUX_MODE0)   /* P9-26 UART1_RX */
        AM33XX_PADCONF(AM335X_PIN_UART1_TXD, PIN_OUTPUT_PULLDOWN, MUX_MODE0)    /* P9-24 UART1_TX */
    >;
};

uart2_pins: pinmux_uart2_pins {
    pinctrl-single,pins = <
        AM33XX_PADCONF(AM335X_PIN_SPI0_SCLK, PIN_INPUT_PULLUP, MUX_MODE1)   /* P9-22 UART2_RX */
        AM33XX_PADCONF(AM335X_PIN_SPI0_D0, PIN_OUTPUT_PULLDOWN, MUX_MODE1)      /* P9-21 UART2_TX */
    >;
};

uart4_pins: pinmux_uart4_pins {
    pinctrl-single,pins = <
        AM33XX_PADCONF(AM335X_PIN_GPMC_WAIT0, PIN_INPUT, MUX_MODE6)     /* P9-11 UART4_RX */    
        AM33XX_PADCONF(AM335X_PIN_GPMC_WPN, PIN_OUTPUT_PULLDOWN, MUX_MODE6) /* P9-13 UART4_TX */    
    >;
};

Once the board boots - I can SSH into it from Ethernet. Here's the output from pinctrl and serial:

root@beaglebone-yocto:~# cat /sys/kernel/debug/pinctrl/pinctrl-maps 
Pinctrl maps:
device 44e10800.pinmux
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_clkout2_pin
function pinmux_clkout2_pin

device 48022000.serial
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_uart1_pins
function pinmux_uart1_pins

device 48024000.serial
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_uart2_pins
function pinmux_uart2_pins

device 4819c000.i2c
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_i2c2_pins
function pinmux_i2c2_pins

device 481a8000.serial
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_uart4_pins
function pinmux_uart4_pins

device 4a100000.switch
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group cpsw_default
function cpsw_default

device 4a100000.switch
state sleep
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group cpsw_sleep
function cpsw_sleep

device 4a101000.mdio
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group davinci_mdio_default
function davinci_mdio_default

device 4a101000.mdio
state sleep
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group davinci_mdio_sleep
function davinci_mdio_sleep

device 44e09000.serial
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_uart0_pins
function pinmux_uart0_pins

device 44e0b000.i2c
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_i2c0_pins
function pinmux_i2c0_pins

device 48060000.mmc
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_mmc1_pins
function pinmux_mmc1_pins

device 481d8000.mmc
state default
type MUX_GROUP (2)
controlling device 44e10800.pinmux
group pinmux_emmc_pins
function pinmux_emmc_pins

root@beaglebone-yocto:~# cat /proc/tty/driver/serial
serinfo:1.0 driver revision:
0: uart:8250 mmio:0x481A8000 irq:35 tx:871 rx:0 RTS|CTS|DTR|DSR
1: uart:8250 mmio:0x48022000 irq:24 tx:0 rx:0 CTS|DSR|CD|RI
2: uart:8250 mmio:0x48024000 irq:25 tx:0 rx:0 CTS|DSR
3: uart:8250 mmio:0x44E09000 irq:18 tx:0 rx:0 CTS|D

As you can see, UART4 gets mapped to /dev/ttyS0 and UART0 gets mapped to /dev/ttyS3 after bootup.

I'm not sure why UART4 gets mapped to ttyS0 and not ttyS4.

I can't even see /dev/ttyS4 despite it being an alias in the am33xx.dtsi

root@beaglebone-yocto:~# ls -la /dev/ttyS*
crw--w---- 1 root tty     4, 64 Mar  9 12:45 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 Jan  1  2000 /dev/ttyS1
crw-rw---- 1 root dialout 4, 66 Jan  1  2000 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 Jan  1  2000 /dev/ttyS3

Beaglebone黑色运行Yocto Poky的修改设备树启用UART4引起内核停止

茶花眉 2025-02-19 18:23:37

制作一个将第二个日期的最低设置为第一个日期的脚本

var a = document.getElementById("a");
var b = document.getElementById("b");

a.addEventListener("input", function() {
  b.min = a.value;
});

a.min = new Date().getFullYear()+"-"+new Date().getDate()+"-"+(new Date().getMonth()+1);
<input type="date" id="a"> From<br>
<input type="date" id="b"> To

Make a script that will set the minimum of the second date to the first date

var a = document.getElementById("a");
var b = document.getElementById("b");

a.addEventListener("input", function() {
  b.min = a.value;
});

a.min = new Date().getFullYear()+"-"+new Date().getDate()+"-"+(new Date().getMonth()+1);
<input type="date" id="a"> From<br>
<input type="date" id="b"> To

使用香草JavaScript进行酒店预订的最低限制和最大日期

茶花眉 2025-02-19 13:45:32

它检查是否存在填充表单字段的最小数量并具有输入。如果是这种情况,请激活提交按钮

将该逻辑放在组验证器中。
这是一个例子:
formGroup验证器

It checks if the minimum number of filled form fields are present and have input. If this is the case, the submit button is activated

Put that logic in a group validator, then.
Here's an example:
FormGroup validator

手动设置表单上的验证

茶花眉 2025-02-19 12:10:44

是的,有一个适当的文档用于从模拟器中导入/导出firestore数据,您可以参考此链接导出和导入模拟器数据

Yes, there is a proper documentation for importing/exporting Firestore data from the emulator you may refer to this link Export and import emulator data.

如何从Firestore数据库模拟器中导出数据

茶花眉 2025-02-18 20:11:25

如果要等待某些呼叫的结束,则必须将函数标记为异步并等待函数调用。

我试图预测您的 usefoo()挂钩的结构,这是我的更改:

const useFoo = (data) => {
  const [ loading, setLoading ] = React.useState(false)
  const [ success, setSuccess ] = React.useState()
  const [ data, setData ] = React.useState()
  const [ error, setError ] = React.useState()

  const fetch = React.useCallback(async () => {
    setLoading(true)

    await axios({
      url, // TODO: pass your url
      headers: {}, // TODO: pass your headers
      method: 'get'
    })
      .then((response) => {
        setSuccess(response.status)
        setData(response.data)
      })
      .catch((error) => {
        setError(error)
      })
      .finally(() => setLoading(false))
  }, [ setSuccess ])

  const update = React.useCallback(
    async () => {
      setLoading(true)

      await axios({
        url, // TODO: pass your url
        headers: {}, // TODO: pass your headers
        method: 'put',
        data,
        responseType: 'json'
      })
        .then((response) => {
          setSuccess(response.status)
        })
        .catch((error) => {
          setError(error)
        })
        .finally(() => setLoading(false))
    },
    [ data ]
  )

  return {
    data,
    fetch,
    loading,
    success,
    update,
    error
  }
}

使用钩子的组件可能看起来像这样:

const YourComponent = () => {
  const { update, fetch, data, success } = useFoo(foo)

  const onClickHandler = async () => {
    await update()

    if (success === 200) {
      await fetch()
      // do some checks and if ok route
    } else {
      // do something else
    }
  }

  return null
}

等待关键字迫使功能要阻止,直到函数调用完成。

If you want to wait for the end of certain calls, you must mark the function as async and wait for the function call.

I tried to anticipate the structure of your useFoo() hook, and here are my changes:

const useFoo = (data) => {
  const [ loading, setLoading ] = React.useState(false)
  const [ success, setSuccess ] = React.useState()
  const [ data, setData ] = React.useState()
  const [ error, setError ] = React.useState()

  const fetch = React.useCallback(async () => {
    setLoading(true)

    await axios({
      url, // TODO: pass your url
      headers: {}, // TODO: pass your headers
      method: 'get'
    })
      .then((response) => {
        setSuccess(response.status)
        setData(response.data)
      })
      .catch((error) => {
        setError(error)
      })
      .finally(() => setLoading(false))
  }, [ setSuccess ])

  const update = React.useCallback(
    async () => {
      setLoading(true)

      await axios({
        url, // TODO: pass your url
        headers: {}, // TODO: pass your headers
        method: 'put',
        data,
        responseType: 'json'
      })
        .then((response) => {
          setSuccess(response.status)
        })
        .catch((error) => {
          setError(error)
        })
        .finally(() => setLoading(false))
    },
    [ data ]
  )

  return {
    data,
    fetch,
    loading,
    success,
    update,
    error
  }
}

The component that uses the hook might look something like this:

const YourComponent = () => {
  const { update, fetch, data, success } = useFoo(foo)

  const onClickHandler = async () => {
    await update()

    if (success === 200) {
      await fetch()
      // do some checks and if ok route
    } else {
      // do something else
    }
  }

  return null
}

The await keyword forces the function to block until the function call is finished.

对1个功能中的Axios请求进行反应

茶花眉 2025-02-18 08:08:31

一种可能的解决方案是创建自己的分配器 std ::分配器是无状态的,但是您可以实现 max_size()成员函数,该功能应返回带有最大元素数的成员变量的值。

一个示例将从C ++ 11起作用至少至少C ++ 20:

template<class T>
struct limited_allocator : public std::allocator<T> {
    using value_type = typename std::allocator<T>::value_type;
    using size_type = typename std::allocator<T>::size_type;
    using difference_type = std::ptrdiff_t;
    using propagate_on_container_move_assignment = std::true_type;

    using is_always_equal = std::false_type; // not needed since C++23

#if __cplusplus < 201703L
    using pointer = typename std::allocator<T>::pointer;
    using const_pointer = typename std::allocator<T>::const_pointer;
    using reference = typename std::allocator<T>::reference;
    using const_reference = typename std::allocator<T>::const_reference;

    template<class U> struct rebind {
        typedef limited_allocator<U> other;
    };
#endif
    
    // No default constructor - it needs a limit:
    constexpr limited_allocator(size_type max_elements) noexcept :
        m_max_elements(max_elements) {}

    constexpr limited_allocator( const limited_allocator& other ) noexcept = default;

    template< class U >
    constexpr limited_allocator( const limited_allocator<U>& other ) noexcept :
        m_max_elements(other.m_max_elements) {}

    // Implementing this is what enforces the limit:
    size_type max_size() const noexcept { return m_max_elements; }

private:
    size_type m_max_elements;
};

由于此分配器并非无状态,因此您最好也实现非成员比较功能:

template< class T1, class T2 >
constexpr bool operator==(const limited_allocator<T1>& lhs,
                          const limited_allocator<T2>& rhs ) noexcept {
    return &lhs == &rhs;
}

template< class T1, class T2 >
constexpr bool operator!=(const limited_allocator<T1>& lhs,
                          const limited_allocator<T2>& rhs ) noexcept {
    return &lhs != &rhs;
}

用法示例,其中>向量可以保留 1 元素仅:

int main() {
    std::vector<int, limited_allocator<int>> vec(limited_allocator<int>(1));
//                   ^^^^^^^^^^^^^^^^^^^^^^      ^^^^^^^^^^^^^^^^^^^^^^^^^
    try {
        vec.push_back(1);   // one element
        vec.pop_back();     // zero again
        vec.push_back(2);   // one again
        vec.push_back(3);   // here it'll throw
    }
    catch(const std::length_error& ex) {
        std::cout << "length_error: " << ex.what() << '\n';
    }    
    catch(const std::bad_array_new_length& ex) {
        std::cout << "bad_array_new_length: " << ex.what() << '\n';
    }
    catch(const std::bad_alloc& ex) {
        std::cout << "bad_alloc: " << ex.what() << '\n';
    }
}

可能的输出:

length_error: vector::_M_realloc_insert

demo

One possible solution would be to create your own Allocator. std::allocator is stateless, but yours could implement the max_size() member function which should return the value of a member variable that carries the max number of elements.

An example that will work from C++11 up until at least C++20:

template<class T>
struct limited_allocator : public std::allocator<T> {
    using value_type = typename std::allocator<T>::value_type;
    using size_type = typename std::allocator<T>::size_type;
    using difference_type = std::ptrdiff_t;
    using propagate_on_container_move_assignment = std::true_type;

    using is_always_equal = std::false_type; // not needed since C++23

#if __cplusplus < 201703L
    using pointer = typename std::allocator<T>::pointer;
    using const_pointer = typename std::allocator<T>::const_pointer;
    using reference = typename std::allocator<T>::reference;
    using const_reference = typename std::allocator<T>::const_reference;

    template<class U> struct rebind {
        typedef limited_allocator<U> other;
    };
#endif
    
    // No default constructor - it needs a limit:
    constexpr limited_allocator(size_type max_elements) noexcept :
        m_max_elements(max_elements) {}

    constexpr limited_allocator( const limited_allocator& other ) noexcept = default;

    template< class U >
    constexpr limited_allocator( const limited_allocator<U>& other ) noexcept :
        m_max_elements(other.m_max_elements) {}

    // Implementing this is what enforces the limit:
    size_type max_size() const noexcept { return m_max_elements; }

private:
    size_type m_max_elements;
};

Since this allocator isn't stateless, you'd better implement the non-member comparison functions too:

template< class T1, class T2 >
constexpr bool operator==(const limited_allocator<T1>& lhs,
                          const limited_allocator<T2>& rhs ) noexcept {
    return &lhs == &rhs;
}

template< class T1, class T2 >
constexpr bool operator!=(const limited_allocator<T1>& lhs,
                          const limited_allocator<T2>& rhs ) noexcept {
    return &lhs != &rhs;
}

A usage example, in which the vector is allowed to keep 1 element only:

int main() {
    std::vector<int, limited_allocator<int>> vec(limited_allocator<int>(1));
//                   ^^^^^^^^^^^^^^^^^^^^^^      ^^^^^^^^^^^^^^^^^^^^^^^^^
    try {
        vec.push_back(1);   // one element
        vec.pop_back();     // zero again
        vec.push_back(2);   // one again
        vec.push_back(3);   // here it'll throw
    }
    catch(const std::length_error& ex) {
        std::cout << "length_error: " << ex.what() << '\n';
    }    
    catch(const std::bad_array_new_length& ex) {
        std::cout << "bad_array_new_length: " << ex.what() << '\n';
    }
    catch(const std::bad_alloc& ex) {
        std::cout << "bad_alloc: " << ex.what() << '\n';
    }
}

Possible output:

length_error: vector::_M_realloc_insert

Demo

我可以限制C&#x2B;&#x2B; 14向量的大小吗?

茶花眉 2025-02-17 07:29:46

您可以使用列表理解:

[df[["c1", f"c{i}"]] for i in range(2, 51)]

前两个数据范围看起来像:

   c1  c2
0   1   2
1   5   8
2   6   9
3   7   2

   c1  c3
0   1  33
1   5  93
2   6  33
3   7  32

You can use a list comprehension:

[df[["c1", f"c{i}"]] for i in range(2, 51)]

The first two dataframes will look like:

   c1  c2
0   1   2
1   5   8
2   6   9
3   7   2

   c1  c3
0   1  33
1   5  93
2   6  33
3   7  32

将矩阵分开并保存在Python中的单独列表或数组中?

茶花眉 2025-02-17 03:51:29

您应该能够适应您的要求(应在循环中使用):

<?php echo get_post_meta($post->ID,'meta_value_key',true); ?>

You should be able to adapt this to fit your requirement (should be used from within the loop):

<?php echo get_post_meta($post->ID,'meta_value_key',true); ?>

如何在WordPress上获取自定义属性和值

茶花眉 2025-02-17 01:33:09

请使用-USTUPS

select * from (
  select occurs_at_time as start_time, 
    length, 
    'Occurrence' as event_type
  from your_table
  union all
  select occurs_at_time + length as start_time, 
    lead(occurs_at_time) over(order by occurs_at_time) - occurs_at_time - length as length, 
    'Free Time' event_type
  from your_table
)
where length > 0               

如果应用于您的问题中的示例数据,

”在此处输入图像描述”

Use below

select * from (
  select occurs_at_time as start_time, 
    length, 
    'Occurrence' as event_type
  from your_table
  union all
  select occurs_at_time + length as start_time, 
    lead(occurs_at_time) over(order by occurs_at_time) - occurs_at_time - length as length, 
    'Free Time' event_type
  from your_table
)
where length > 0               

if applied to sample data in your question - output is

enter image description here

如何获得比原始表更高的行输出的SQL输出? - 事件的时间表

茶花眉 2025-02-16 12:24:02

您指的是的软件包您要选择它应该用来渲染图形的内容。您可以导入:

  • canvas-constructor/napi-rs
  • canvas-constructor/skia-canvas
  • canvas-constructor/canvas

但您可以' t导入 canvas-constructor 本身。如果选择 NAPI-RS 首先需要安装该软件包。这三个选项的链接是在readme file 中。


包装有两种类型:

  • ES6模块(也用于浏览器,从“ ./ x.js”
  • commonjs (较老) (“ ./ x.js”)

但仍然支持, x = requient 的节点版本中。

Code> requient()您可能会缺少名为 node的依赖性:util 在较旧 尽管该软件包与节点14及以上兼容,但请确保您使用的是最近版本。

The package you refer to requires you to pick what it should use to render graphics. You can import:

  • canvas-constructor/napi-rs or
  • canvas-constructor/skia-canvas or
  • canvas-constructor/canvas

But you can't import canvas-constructor by itself. If you pick napi-rs you would first need to install that package. A link to these three options are in the README file.


There are two types of packages:

  • ES6 Modules (also used in browsers, import x from "./x.js")
  • CommonJS (older but still supported, x = require("./x.js").

The authors of canvas-constructor made sure it works with both.

However, if you use require() you may be missing a dependency named node:util. In older Node versions it's only available when using import.

Because of this, even though the package is listed as compatible with Node 14 and up, make sure you are using a recent version.

“没有出口主要的出口主要定义”错误node.js

茶花眉 2025-02-16 12:01:13

您可以通过在root __模拟__ 文件夹中创建 localforage.ts 文件来模拟此操作。在那里,您可以在此模块中模拟任何值或功能,而嘲笑将自动使用此功能。

// <rootDir>/__mocks__/localforage.ts

const mock = {
  setItem: async () => undefined,
  getItem: async () => undefined,
  removeItem: async () => undefined,
};

export default mock;

docs

You can mock this with creating a localforage.ts file in the root __mocks__ folder. There you can mock any values or functions in this module and Jest will automatically use this.

// <rootDir>/__mocks__/localforage.ts

const mock = {
  setItem: async () => undefined,
  getItem: async () => undefined,
  removeItem: async () => undefined,
};

export default mock;

Docs

如何用嘲笑模拟localforage.getItem()?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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