波浪屿的海角声

文章 评论 浏览 29

波浪屿的海角声 2025-02-04 16:24:14

不要尝试将零添加回零,只是不要首先删除它们,告诉 pandas.read_csv 列是字符串:输出:

pd.read_csv('test_stuff.csv', dtype={'Phone': 'str'})

输出:

  Person        Phone
0    One  08001111111
1    Two  08002222222
2  Three  08003333333

Don't try to add the zeros back, just don't delete them in the first place by telling pandas.read_csv that you column is a string:

pd.read_csv('test_stuff.csv', dtype={'Phone': 'str'})

output:

  Person        Phone
0    One  08001111111
1    Two  08002222222
2  Three  08003333333

如何使用Pandas从CSV中打印出CSV的电话号码?

波浪屿的海角声 2025-02-04 10:49:07

确保您已将所有必需的特权授予了您为管理数据库的创建的用户。

使用 psql 您可以使用以下命令进行:

 GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;

此外,您应该为Postgres DB安装 psycopg2 与Django配对。

在终端执行以下执行:

pip install psycopg2

Make sure that you have granted all required privileges to a user you have created for managing your database.

Using psql you can do so with the following command:

 GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;

Additionally, you ought to have psycopg2 installed for the postgres DB to pair with Django.

In a terminal execute the following:

pip install psycopg2

在Django和Postgresql DB中运行测试时可以创建数据库

波浪屿的海角声 2025-02-04 08:09:08

使用 data.table 的另一个选项:

library(data.table)
  
setDT(df)[,if(.N > 1) .SD, by=ID]

输出

   ID tmt.pair year month level    tmt      val
1:  1        A 2021     A   Low 1000 C 4.424811
2:  1        A 2021     A   Low 4000 C 4.556058
3:  3        B 2021     J   Low 1000 C 4.396996
4:  3        B 2021     J   Low 4000 C 3.906065
5:  4        B 2020     O   Low 1000 C 5.714706
6:  4        B 2020     O   Low 4000 C 4.891188

dplyr ,其中我们只保留 id> id S 1观察:

library(dplyr)

df %>%
  group_by(ID) %>%
  filter(n() > 1)

Another option using data.table:

library(data.table)
  
setDT(df)[,if(.N > 1) .SD, by=ID]

Output

   ID tmt.pair year month level    tmt      val
1:  1        A 2021     A   Low 1000 C 4.424811
2:  1        A 2021     A   Low 4000 C 4.556058
3:  3        B 2021     J   Low 1000 C 4.396996
4:  3        B 2021     J   Low 4000 C 3.906065
5:  4        B 2020     O   Low 1000 C 5.714706
6:  4        B 2020     O   Low 4000 C 4.891188

Or with dplyr, where we only keep IDs that have more than 1 observation:

library(dplyr)

df %>%
  group_by(ID) %>%
  filter(n() > 1)

如何在R中使用单个唯一ID删除行?

波浪屿的海角声 2025-02-04 08:01:40

以下三种方法定义了服务的寿命,

  1. addtransient
    每次请求时,都会创建瞬态寿命服务。这一生最适合轻巧的无状态服务。

  2. addScoped
    每个请求一次创建一次范围的寿命服务。

  3. 添加
    首次创建Singleton Lifetime服务(如果在此指定实例时运行Configureservices时),然后每个后续请求将使用同一实例。

/a>

想象您有一个ASPNET核心项目。

  • 如果您只想在程序的运行时创建一次对象并每次使用相同的对象,则应使用添加ingingleton。

  • 如果您希望每次在程序运行时收到请求时再次成为新(),则应使用AddScoped()。

  • 如果您想要一个new()每个请求和响应的对象,则必须使用addTransient。

The below three methods define the lifetime of the services,

  1. AddTransient
    Transient lifetime services are created each time they are requested. This lifetime works best for lightweight, stateless services.

  2. AddScoped
    Scoped lifetime services are created once per request.

  3. AddSingleton
    Singleton lifetime services are created the first time they are requested (or when ConfigureServices is run if you specify an instance there) and then every subsequent request will use the same instance.

Reference here

Imagine you have a aspnet-core project.

  • If you want to create an object only once during the program's runtime and use the same object each time, you should use addingingleton.

  • If you want an object to be new() again every time it receives a request while the program is running, you should use addscoped().

  • If you want an object to new() every request and response, you must use AddTransient.

Example value of 3 methods

Understanding with an infographic

为什么使用addScoped()而不是addsingleton()?

波浪屿的海角声 2025-02-04 01:00:56

scanf()自动在尝试解析字符以外的其他转换之前。字符格式(主要是%c ;还扫描集%[…] - 和%n )是例外;他们不跳过空格。

使用“%c” 带有领先的空白以跳过可选的空白。请勿在 scanf()格式字符串中使用尾随空白。

请注意,这仍然不会消耗输入流中留下的任何尾随空格,甚至没有到一行的末端,因此,如果还使用 getchar() fgets() 在同一输入流上。我们只是让Scanf在转换之前跳过Whitespace ,就像%D 和其他非字符转换一样。


请注意,非空间“指令”(使用 scanf中的文字文本(“ order =%d”,& order); 也不会跳过whitespace。文字顺序必须匹配要读取的下一个字符。

因此,您可能想要“ order =%d” 如果要跳过上一行的新线。

The scanf() function skips leading whitespace automatically before trying to parse conversions other than characters. The character formats (primarily %c; also scan sets %[…] — and %n) are the exception; they don't skip whitespace.

Use " %c" with a leading blank to skip optional white space. Do not use a trailing blank in a scanf() format string.

Note that this still doesn't consume any trailing whitespace left in the input stream, not even to the end of a line, so beware of that if also using getchar() or fgets() on the same input stream. We're just getting scanf to skip over whitespace before conversions, like it does for %d and other non-character conversions.


Note that non-whitespace "directives" (to use POSIX scanf terminology) other than conversions, like the literal text in scanf("order = %d", &order); doesn't skip whitespace either. The literal order has to match the next character to be read.

So you probably want " order = %d" there if you want to skip a newline from the previous line but still require a literal match on a fixed string, like this question.

scanf()将newline字符留在缓冲区中

波浪屿的海角声 2025-02-03 21:23:46

更新下面的代码(相关问题要了解第一个代码调整:为什么MinMax(0,1fr)为长期元素工作时1fr dryn nn 't?

* {
  margin: 0;
}

.container {
  display: flex;
  justify-content: center;
  background-color: firebrick;
}

.form {
  display: flex;
  flex-direction: column;
  padding: 2rem;
  margin: 2rem;
  width: 25rem;
  background-color: white;
}
.content {
  border: 1px solid red;
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr)); /* here */
  grid-gap: 4rem;
}

/* here */
input {
  max-width: 100%;
  box-sizing: border-box;
}
<div class="container">
  <form class="form">
    <div class="content">
      <div class="field">
        <label for="title" class="label">Title</label>
        <input type="text" placeholder="Job Title" id="title" class="input">
        <i class="icon icon--success"></i>
        <i class="icon icon--fail">
        </i>
        <small class="error-msg"></small>
      </div>
      <div class="field">
        <label for="company" class="label">Company</label>
        <select name="company" id="company" class="input">
            <!-- options added in js -->
        </select>
        <i class="icon icon--success"></i>
        <i class="icon icon--fail"></i>
        <small class="error-msg"></small>
      </div>

      <div class="field">
        <label for="location" class="label">Location</label>
        <select name="location" id="location" class="input">
            <!-- options added in js -->
        </select>                        
        <i class="icon"></i>
        <i class="icon"></i>
        <small class="error-msg"></small>
      </div>

      <div class="field">
        <label for="wage" class="label">Wage</label>
        <input type="text" placeholder="Wage" id="wage" class="input">
        <i class="icon icon--success"></i>
        <i class="icon icon--fail"></i>
        <small class="error-msg"></small>
      </div>

      <div class="field">
        <label for="type" class="new-job__label">Type</label>
        <select name="type" id="type" class="input">
          <!-- options added in js -->
        </select>
        <i class="icon icon--success"></i>
        <i class="icon icon--fail"></i>
        <small class="error-msg"></small>
      </div>

      <div class="field">
        <label for="position" class="label">Position</label>
        <select name="position" id="position" class="input">
          <!-- options added in js -->
        </select>
        <i class="icon icon--success"></i>
        <i class="icon icon--fail"></i>
        <small class="error-msg"></small>
      </div>

      <div class="field">
        <label for="pqe" class="label">PQE</label>
        <select name="pqe" id="pqe" class="input">
            <!-- options added in js -->
        </select>
        <i class="icon icon--success"></i>
        <i class="icon icon--fail"></i>
        <small class="error-msg"></small>
      </div>

      <div class="field">
        <label for="featured" class="label">Featured</label>
        <select name="featured" id="featured" class="input">
          <!-- options added in js -->
        </select>
        <i class="icon icon--success"></i>
        <i class="icon icon--fail"></i>
        <small class="error-msg"></small>
      </div>
    </div>
    <button class="new-job__submit">Submit</button>

  </form>
</div>

Update the code like below (related question to understand the first code adjustment: Why does minmax(0, 1fr) work for long elements while 1fr doesn't?)

* {
  margin: 0;
}

.container {
  display: flex;
  justify-content: center;
  background-color: firebrick;
}

.form {
  display: flex;
  flex-direction: column;
  padding: 2rem;
  margin: 2rem;
  width: 25rem;
  background-color: white;
}
.content {
  border: 1px solid red;
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr)); /* here */
  grid-gap: 4rem;
}

/* here */
input {
  max-width: 100%;
  box-sizing: border-box;
}
<div class="container">
  <form class="form">
    <div class="content">
      <div class="field">
        <label for="title" class="label">Title</label>
        <input type="text" placeholder="Job Title" id="title" class="input">
        <i class="icon icon--success"></i>
        <i class="icon icon--fail">
        </i>
        <small class="error-msg"></small>
      </div>
      <div class="field">
        <label for="company" class="label">Company</label>
        <select name="company" id="company" class="input">
            <!-- options added in js -->
        </select>
        <i class="icon icon--success"></i>
        <i class="icon icon--fail"></i>
        <small class="error-msg"></small>
      </div>

      <div class="field">
        <label for="location" class="label">Location</label>
        <select name="location" id="location" class="input">
            <!-- options added in js -->
        </select>                        
        <i class="icon"></i>
        <i class="icon"></i>
        <small class="error-msg"></small>
      </div>

      <div class="field">
        <label for="wage" class="label">Wage</label>
        <input type="text" placeholder="Wage" id="wage" class="input">
        <i class="icon icon--success"></i>
        <i class="icon icon--fail"></i>
        <small class="error-msg"></small>
      </div>

      <div class="field">
        <label for="type" class="new-job__label">Type</label>
        <select name="type" id="type" class="input">
          <!-- options added in js -->
        </select>
        <i class="icon icon--success"></i>
        <i class="icon icon--fail"></i>
        <small class="error-msg"></small>
      </div>

      <div class="field">
        <label for="position" class="label">Position</label>
        <select name="position" id="position" class="input">
          <!-- options added in js -->
        </select>
        <i class="icon icon--success"></i>
        <i class="icon icon--fail"></i>
        <small class="error-msg"></small>
      </div>

      <div class="field">
        <label for="pqe" class="label">PQE</label>
        <select name="pqe" id="pqe" class="input">
            <!-- options added in js -->
        </select>
        <i class="icon icon--success"></i>
        <i class="icon icon--fail"></i>
        <small class="error-msg"></small>
      </div>

      <div class="field">
        <label for="featured" class="label">Featured</label>
        <select name="featured" id="featured" class="input">
          <!-- options added in js -->
        </select>
        <i class="icon icon--success"></i>
        <i class="icon icon--fail"></i>
        <small class="error-msg"></small>
      </div>
    </div>
    <button class="new-job__submit">Submit</button>

  </form>
</div>

CSS网格:网格差距导致项目溢出?

波浪屿的海角声 2025-02-03 06:03:58

您可以使用两个 div 对其进行操作。

  1. 第一个Div与Border
  2. Second Div用于影子盒
.outer{
  border:2px solid #333;
  width:200px;
  height:150px;
  border-radius:20px;
}

.inner{
-webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
width:180px;
height:130px;
margin:10px;
}
<div class="outer">
  <div class="inner">
  </div>
</div>

You can use two div do to it.

  1. first div with border
  2. second div for shadow box

.outer{
  border:2px solid #333;
  width:200px;
  height:150px;
  border-radius:20px;
}

.inner{
-webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
width:180px;
height:130px;
margin:10px;
}
<div class="outer">
  <div class="inner">
  </div>
</div>

如何在另一个盒子上创建一个CSS框?

波浪屿的海角声 2025-02-02 05:25:43

从您在评论中共享的错误中,看起来您在定义的控制器时要在HTTP post请求中进行HTTP。

将您的控制器注释更改为以下任何一个

@PostMapping("/saveContact")

@RequestMapping(path = "/saveContact", method = RequestMethod.POST)

From the error you shared in comments, looks like you're making a HTTP POST request while the controller you've defined is for HTTP GET.

Change your controller annotations to the either of the following

@PostMapping("/saveContact")

or

@RequestMapping(path = "/saveContact", method = RequestMethod.POST)

嗨,我面对春季靴子的问题。这是我的问题:我的形式&amp;表成功开发了,但是数据不能存储在MySQL(Spring Boot)中

波浪屿的海角声 2025-02-01 03:44:51

给定一个包含您想要的所有特征值的对角矩阵,您可以使用随机(但可逆)矩阵的相似性转换来完成您想要的事情:

>> lambda = [-1 -2 -3]   % These are the eigenvalues you want
lambda =
  -1    -2    -3

>> A = diag(lambda)
A =
-1     0     0
 0    -2     0
 0     0    -3

>> eig(A)
 ans =
 -3
 -2
 -1

>> S = rand(size(A));   % Random matrix of compatible size with A.
>> B = inv(S)*A*S       % Random matrix with desired eigenvalues, using similarity transformation
B =
-2.7203   -0.5378   -0.9465
 2.0427   -0.1766    1.2659
-2.0817   -1.8974   -3.1031

>> eig(B)
ans =
-3.0000
-1.0000
-2.0000

Given a diagonal matrix containing all the eigenvalues you want, you can use a similarity transformation of a random (but invertible) matrix to do what you want:

>> lambda = [-1 -2 -3]   % These are the eigenvalues you want
lambda =
  -1    -2    -3

>> A = diag(lambda)
A =
-1     0     0
 0    -2     0
 0     0    -3

>> eig(A)
 ans =
 -3
 -2
 -1

>> S = rand(size(A));   % Random matrix of compatible size with A.
>> B = inv(S)*A*S       % Random matrix with desired eigenvalues, using similarity transformation
B =
-2.7203   -0.5378   -0.9465
 2.0427   -0.1766    1.2659
-2.0817   -1.8974   -3.1031

>> eig(B)
ans =
-3.0000
-1.0000
-2.0000

如何在MATLAB中为给定的特征值生成随机矩阵?

波浪屿的海角声 2025-01-31 10:21:16

只需在内部检查条件检查 new-break长度内部即可。

您还可以用本地查找表限制对允许的核苷酸进行检查。

在输入中注意到三(3) n 。 wiki norefollow noreferrer“> nucletide- GAP) ,但预期输出&amp;您的错误输出没有它们。

#define LINE_BREAK_LEN  50
void
output (const char *seq, const int len) {
    char nlt [256] = {0};
    nlt ['A'] = nlt['G'] = nlt['C'] = nlt['T'] = nlt['U'] = 1;
    //nlt ['a'] = nlt['g'] = nlt['c'] = nlt['t'] = nlt['u'] = 1; // in case you want to allow lower-case too

    for (int i = 0, j = 0; i < len; i++) {
        if (nlt [(unsigned char) seq[i]]) {
            putc (seq[i], stdout);
            j++;
            if (0 == (j % LINE_BREAK_LEN))
                putc ('\n', stdout);
        }
    }
    putc ('\n', stdout);
}

Just move the if condition checking new-break-length inside.

You can also restrict checking against allowed nucleotides with local look-up table.

Noticed three(3) Ns in the input. Wiki Nucleotide - Abbreviation Codes, says any base (not a gap), but expected output & your erroneous output don't have them.

#define LINE_BREAK_LEN  50
void
output (const char *seq, const int len) {
    char nlt [256] = {0};
    nlt ['A'] = nlt['G'] = nlt['C'] = nlt['T'] = nlt['U'] = 1;
    //nlt ['a'] = nlt['g'] = nlt['c'] = nlt['t'] = nlt['u'] = 1; // in case you want to allow lower-case too

    for (int i = 0, j = 0; i < len; i++) {
        if (nlt [(unsigned char) seq[i]]) {
            putc (seq[i], stdout);
            j++;
            if (0 == (j % LINE_BREAK_LEN))
                putc ('\n', stdout);
        }
    }
    putc ('\n', stdout);
}

与任意新线的重新格式化文本相等的行

波浪屿的海角声 2025-01-31 06:27:55

答案是要卸载并重新安装Python,这次告诉它设置环境变量。那做了这个问题。

The answer was to uninstall and reinstall python, this time telling it to set environment variables. That did the trick.

当我尝试使用pip in命令提示符时遇到致命的python错误

波浪屿的海角声 2025-01-31 01:19:23

我相信您的目标如下。

  • 您希望每周每周插入水平线。
  • 运行脚本时,在运行“清除Google Sheet”的脚本后,运行“将DF_Final写为Google Sheep”的脚本是运行的。
  • 数据是从第1个选项卡中的单元格“ B7”放置的。
  • 您想使用python使用googleapis实现这一目标。

在您的脚本中,以下修改后的脚本怎么样?

修改后的脚本:

请设置 dreversheet_id sheet_id 的值。

spreadsheet_id = "###" # Please set Spreadsheet ID.
sheet_id = 0  # Please set the sheet ID.

# 1. Clear sheet. In this case, the values and the horizontal lines are removed.
service.spreadsheets().batchUpdate(
    spreadsheetId=spreadsheet_id, body={"requests": [{
        "repeatCell": {
            "range": {
                "sheetId": sheet_id
            },
            "fields": "userEnteredValue,userEnteredFormat.borders"
        }
    }
    ]}).execute()

# 2. Put the values from the dataframe to Spreadsheet.
cell_range_insert = 'B7'
# values = df_final.to_json() # It seems that this is not used.
# body = {'values': values} # It seems that this is not used.
response_date = service.spreadsheets().values().append(
    spreadsheetId=spreadsheet_id,
    valueInputOption='RAW',
    range=cell_range_insert,
    body=dict(
        majorDimension='ROWS',
        values=df_final.T.reset_index().T.values.tolist()
    )
).execute()

# 3. Set the horizontal lines.
temp = -1
n = []
for index, row in df_final.iloc[:, 5:8].iterrows():
    s = ''.join(row.astype(str).tolist())
    if temp != s:
        n.append(index)
        temp = s
offset = 7
requests = [{
    "repeatCell": {
        "cell": {
            "userEnteredFormat": {
                "borders": {
                    "top": {
                        "style": "SOLID_THICK"
                    }
                }
            }
        },
        "range": {
            "sheetId": sheet_id,
            "startRowIndex": e + offset,
            "endRowIndex": e + 1 + offset,
            "startColumnIndex": 1,
            "endColumnIndex": 10
        },
        "fields": "userEnteredFormat.borders"
    }
} for e in n]
service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id, body={"requests": requests}).execute()
  • 运行此脚本时,使用batchupdate方法清除表。在这种情况下,删除了值和水平线。而且,数据将放在电子表格上。然后,使用batchupdate方法放置水平线(每个周末的“ B”列至“ J”)。

  • 为了检查放置边框的行号,我使用了列“ G”,“ H”,“ I”的值。

  • 在此示例中,我使用 solid_thick 作为边框。如果您想更改此问题,请更改它。 ref ref

注意:

  • 上面脚本检查列“ G”,“ H”,“ I”。如果您只想检查“ i”列,而不是列“ g”,“ h”,“ i”,作为一个简单的修改,请按以下方式修改上述脚本。

    • 来自

        index,df_final.iloc [:,5:8] .ITERROWS():
       
    • to

       索引,在df_final.iloc [:,7:8]中行().iterrows():
       

文献:

I believe your goal is as follows.

  • You want to insert the horizontal line every each Week ends to the Spreadsheet.
  • When the script is run, after the script of "Clear the Google Sheet:" was run, the script of "Write df_final to Google Sheet:" is run.
  • The data is put from the cell "B7" in the 1st tab.
  • You want to achieve this using googleapis for python.

In your script, how about the following modified script?

Modified script:

Please set the values of spreadsheet_id and sheet_id.

spreadsheet_id = "###" # Please set Spreadsheet ID.
sheet_id = 0  # Please set the sheet ID.

# 1. Clear sheet. In this case, the values and the horizontal lines are removed.
service.spreadsheets().batchUpdate(
    spreadsheetId=spreadsheet_id, body={"requests": [{
        "repeatCell": {
            "range": {
                "sheetId": sheet_id
            },
            "fields": "userEnteredValue,userEnteredFormat.borders"
        }
    }
    ]}).execute()

# 2. Put the values from the dataframe to Spreadsheet.
cell_range_insert = 'B7'
# values = df_final.to_json() # It seems that this is not used.
# body = {'values': values} # It seems that this is not used.
response_date = service.spreadsheets().values().append(
    spreadsheetId=spreadsheet_id,
    valueInputOption='RAW',
    range=cell_range_insert,
    body=dict(
        majorDimension='ROWS',
        values=df_final.T.reset_index().T.values.tolist()
    )
).execute()

# 3. Set the horizontal lines.
temp = -1
n = []
for index, row in df_final.iloc[:, 5:8].iterrows():
    s = ''.join(row.astype(str).tolist())
    if temp != s:
        n.append(index)
        temp = s
offset = 7
requests = [{
    "repeatCell": {
        "cell": {
            "userEnteredFormat": {
                "borders": {
                    "top": {
                        "style": "SOLID_THICK"
                    }
                }
            }
        },
        "range": {
            "sheetId": sheet_id,
            "startRowIndex": e + offset,
            "endRowIndex": e + 1 + offset,
            "startColumnIndex": 1,
            "endColumnIndex": 10
        },
        "fields": "userEnteredFormat.borders"
    }
} for e in n]
service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id, body={"requests": requests}).execute()
  • When this script is run, the sheet is cleared using the batchUpdate method. In this case, both the values and the horizontal lines are removed. And, the data is put to the Spreadsheet. And then, the horizontal lines (columns "B" to "J" for every weekend) are put using the batchUpdate method.

  • In order to check the row numbers for putting the border, I used the values of columns "G", "H", "I".

  • In this sample, I used SOLID_THICK as the border. If you want to change this, please change it. Ref

Note:

  • The above script checks the columns "G", "H", "I". If you want to check only the column "I" instead of the columns "G", "H", "I", as a simple modification, please modify the above script as follows.

    • From

        for index, row in df_final.iloc[:, 5:8].iterrows():
      
    • To

        for index, row in df_final.iloc[:, 7:8].iterrows():
      

References:

将Python DataFrame发布到Gsheet:根据日期绘制一组数据的边界

波浪屿的海角声 2025-01-30 19:22:14

这可以帮助您:

#!/bin/bash

echo "script started at $(date +'%Y-%m-%dT%H:%M:%S%:z')"

echo "doing something"
sleep 2

echo "script finished at $(date +'%Y-%m-%dT%H:%M:%S%:z')"

如果调用完整命令对您来说笨拙,您可能需要创建一个别名。

This can help you:

#!/bin/bash

echo "script started at $(date +'%Y-%m-%dT%H:%M:%S%:z')"

echo "doing something"
sleep 2

echo "script finished at $(date +'%Y-%m-%dT%H:%M:%S%:z')"

You might want to create an alias if calling the full command looks clumsy to you.

日期命令作为bash脚本中的变量。需要每次调用,而不是在可变声明中调用

波浪屿的海角声 2025-01-30 14:48:40

这也可能很有用,所以我想我会在这里添加。

如果您想根据项目的值选择一个值,而不是该项目的索引,则可以执行以下操作:

您的选择列表:

<select id="selectBox">
    <option value="A">Number 0</option>
    <option value="B">Number 1</option>
    <option value="C">Number 2</option>
    <option value="D">Number 3</option>
    <option value="E">Number 4</option>
    <option value="F">Number 5</option>
    <option value="G">Number 6</option>
    <option value="H">Number 7</option>
</select>

jQuery:

$('#selectBox option[value=C]').attr('selected', 'selected');

$('#selectBox option[value=C]').prop('selected', true);

所选的项目现在为“ 2号”。

This may also be useful, so I thought I'd add it here.

If you would like to select a value based on the item's value and not the index of that item then you can do the following:

Your select list:

<select id="selectBox">
    <option value="A">Number 0</option>
    <option value="B">Number 1</option>
    <option value="C">Number 2</option>
    <option value="D">Number 3</option>
    <option value="E">Number 4</option>
    <option value="F">Number 5</option>
    <option value="G">Number 6</option>
    <option value="H">Number 7</option>
</select>

The jquery:

$('#selectBox option[value=C]').attr('selected', 'selected');

$('#selectBox option[value=C]').prop('selected', true);

The selected item would be "Number 2" now.

jQuery集选择索引

波浪屿的海角声 2025-01-30 12:55:31

除了Mernst的接受答案外,我还找到了用于错误框架的Nullaway插件。
教程: https://wwwww.baeldung.com/java-nullaway
主页: https://github.com/uber/nullaway

重点,到目前为止,它们似乎都与我需要的东西相匹配。

In addition to the accepted answer from mernst, I have also found the NullAway plugin for the ErrorProne framework.
Tutorial: https://www.baeldung.com/java-nullaway
Main page: https://github.com/uber/NullAway

Will have to try out both at some point, so far they seem both to match what I need.

编译检查插件框架以执行无零返回

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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