玩心态

文章 评论 浏览 30

玩心态 2025-02-10 03:42:07

问题与数据库的限制有关。它加快了多线程的过程,但是数据库一次限制了100个ping。在任何给定时间增加此连接或最大数量到小于100的数字。

The problem was related to a restriction on the database. It speeds up the process to multithread, but the database has a restriction of 100 pings at a single time. Either increase this connection or max out the number of threads at any given time to a number less than 100.

使用需要锁定的词典使用多处理

玩心态 2025-02-10 03:01:37

我要补充说,您遇到的一些问题是您从不正确的定义开始。建议的functor -

type Functor [A any, B any] interface{
                  // ^ Functor should wrap a single type ⚠️
  fmap(f func(A)B) B
                // ^ should return Functor-wrapped B ⚠️
}

解决您上述问题,这是我们要写的

type Functor[A any] interface{
  fmap[B any](f func(A)B) Functor[B]
}

请警告我们给我们直接给我们直接 有关您面临的问题的反馈 -

interface method must have no type parameters
undefined: B

@jub0bs在链接的答案中指出,方法可能不使用其他类型的参数

I would add that some of the issue you are having is that you started with an incorrect definition. There should be some immediate red flags in the proposed Functor -

type Functor [A any, B any] interface{
                  // ^ Functor should wrap a single type ⚠️
  fmap(f func(A)B) B
                // ^ should return Functor-wrapped B ⚠️
}

Fixing the issue you have above, this is what we'd like to write -

type Functor[A any] interface{
  fmap[B any](f func(A)B) Functor[B]
}

However Go warns us giving us direct feedback on the issue you are facing -

interface method must have no type parameters
undefined: B

As @jub0bs points out in the linked answer, methods may not take additional type arguments.

我如何模仿``fmap''?

玩心态 2025-02-09 21:46:06

您标题问题的答案:是的,弗雷托斯(Freertos)处理OS对象的“并发”创建,这是安全的。您可以编写安全管理的函数。

但是,您共享的代码并不是线程安全/重新进入它的存储方式并处理这些创建的对象。如您所见,线程可能会迭代您的信号量数组,找到空,创建信号量并开始分配它,然后将任务切换为“转换”,而另一个线程则相同,当它返回时,您的原始线程将覆盖什么”中断“线程刚刚写的,您已经索要一个条目,并且在某个地方有一个潜在的孤儿信号量,具体取决于弗雷托斯的实施方式。

如何解决?

RTOS提供同步对象,例如静音等。您应该使用它们。

IE操作系统101

The answer to your title question: Yes, FreeRTOS handles "concurrent" creation of OS objects and that's safe. You can write a function that manages this safely.

Your shared code, however, is not thread safe/reentrant with how it stores off and deals with these created objects. As you see yourself, a thread could be iterating your semaphore array, find a NULL, create the semaphore and begin to assign it, then get task switched away and another thread does the same, when it returns your original thread will overwrite what the "interrupting" thread just wrote and you've double claimed an entry and there's a potentially orphan semaphore floating around somewhere, depending on how FreeRTOS is implemented.

How to solve?

The RTOS provides synchronization objects like mutexes, etc. You should use them.

i.e. operating systems 101

在有多个任务调用创建弗雷​​托对象的函数的函数中,安全吗?

玩心态 2025-02-09 21:29:45

您可以检查字符串是否包含另一个字符串作为子字符串,其中 包括 方法:

if (msg.content.toLowerCase().includes('morning')) {
    // ...
}

You can check if a string includes another string as a substring with the includes method:

if (msg.content.toLowerCase().includes('morning')) {
    // ...
}

我可以在JavaScript中编写正则表达式并使用.test()吗?

玩心态 2025-02-09 20:24:43

Alekskamb拥有正确的解决方案。应用索引后,它似乎正在工作。我将V-For编辑为:

            <div v-for="(image, index) in this.images" :key="image">
            <cropper ref="cropper" class="upload-example__cropper"
                     check-orientation :src="image.src"/>
            <button v-if="image.src" class="upload-example__button" @click="crop(index)">Crop</button>
            <!--<div class="upload-example__reset-button" title="Reset Image" @click="reset()"></div>-->
            <div class="upload-example__file-type" v-if="image.type">
                {{ image.type }}
            </div>
        </div>

然后我将裁剪功能编辑为:

            crop(index) {
            const { canvas } = this.$refs.cropper[index].getResult();
            if (canvas) {
                const form = new FormData();
                canvas.toBlob(blob => {
                    form.append('files[]', blob);
                    // Perhaps you should add the setting appropriate file format here
                }, 'image/jpeg');

            }
        },

aleksKamb had the right solution. After applying indexes it appears to be working. I edited the v-for to:

            <div v-for="(image, index) in this.images" :key="image">
            <cropper ref="cropper" class="upload-example__cropper"
                     check-orientation :src="image.src"/>
            <button v-if="image.src" class="upload-example__button" @click="crop(index)">Crop</button>
            <!--<div class="upload-example__reset-button" title="Reset Image" @click="reset()"></div>-->
            <div class="upload-example__file-type" v-if="image.type">
                {{ image.type }}
            </div>
        </div>

And then I edited the cropping function to:

            crop(index) {
            const { canvas } = this.$refs.cropper[index].getResult();
            if (canvas) {
                const form = new FormData();
                canvas.toBlob(blob => {
                    form.append('files[]', blob);
                    // Perhaps you should add the setting appropriate file format here
                }, 'image/jpeg');

            }
        },

Vue -Advanced Cropper(Unturect typeError:this。$ refs.cropper.getResult不是功能)

玩心态 2025-02-09 12:50:10

不要在C ++中使用C。只需使用 std :: vector vector 单词:

std::string word;
std::vector<std::string> words;

while (ss >> word) {
    words.push_back(word);
}

然后您可以打印这样的单个单词:

for (auto& word: words) {
    std::cout << word << '\n';
}

或者如果您想使用索引:

for (std::size_t i = 0; i  < words.size(); ++i) {
    std::cout << i << ": " << words[i] << '\n';
}

您的代码失败的原因是@heapunderrun提到的,这是std :: string :: string有这一事实构造函数。如果您不以某种方式调用构造函数,则字符串将处于不确定状态。当您尝试分配到这样的字符串时,例如:

*(words+count)=ss.str();

您的程序将崩溃。如果您真的想使用手动内存分配,则必须使用 /code> delete。您可以使用malloc()(如果您真的愿意正确构造了您分配的内存。最后,您可能不能安全地使用realloc(),您必须malloc()一个新数组,将所有内容正确复制到新数组,然后> Free()旧数组。

Don't use C in C++. Just use a std::vector to store the words:

std::string word;
std::vector<std::string> words;

while (ss >> word) {
    words.push_back(word);
}

And then you can print the individual words like so:

for (auto& word: words) {
    std::cout << word << '\n';
}

Or if you wish to use indices:

for (std::size_t i = 0; i  < words.size(); ++i) {
    std::cout << i << ": " << words[i] << '\n';
}

The reason why your code fails is, as @heapunderrun mentioned, the fact that std::string has a constructor. If you don't call the constructor in some way, then the string will be in an indeterminate state. When you try to assign to such a string, like in:

*(words+count)=ss.str();

Then your program will crash. If you really want to use manual memory allocation, then you have to use new and delete. You can use malloc() if you really want to, but then you still should use placement new to ensure the std::string objects are correctly constructed inside the memory you allocated. Finally, you probably can't use realloc() safely, you would have to malloc() a new array, copy everything properly to the new array, then free() the old array.

如何修复“监视命令”错误?

玩心态 2025-02-08 19:10:32
for i in range(6):
    num = int(input("Num: "))
    if num % 2 == 0:
        print(liczba)
        break

如果没有所有额外的线条,这将完成您想要的事情。

for i in range(6):
    num = int(input("Num: "))
    if num % 2 == 0:
        print(liczba)
        break

This will do what you want, without all the extra lines you had.

程序必须向用户询问均匀的整数最大六次,如果没有结束

玩心态 2025-02-07 15:22:31
this.getClass().getClassLoader().getResource("filename").getPath()
this.getClass().getClassLoader().getResource("filename").getPath()

如何从资源文件夹加载文件?

玩心态 2025-02-06 10:39:08

如果数字存储在大元素顺序中,并且指针在16个字节边界上对齐,则与memcmp的比较为16个字节边界。它是否更有效将取决于编译器和优化设置。

这是一个修改后的功能:

typedef unsigned __int128 u128_t;  // works for gcc, adjust for your compiler

int compare(const void *p1, const void *p2) {
    const u128_t *v1 = p1;
    const u128_t *v2 = p2;
    return (*v1 > *v2) - (*v1 < *v2);
}

问题是您的目标系统可能使用 Little Endian 顺序(例如:x86 cpus)。如果您的目标是在数组数组中找到数组,那么只要使用相同的比较对数组进行排序,您仍然可以使用此技巧。

使用bsearch需要一个功能指针,该函数指针返回等于0对比较均等的元素的签名值,如果元素指向p1 p1 小于p2指向的一个,否则为正值。这种方法的另一个问题是类型的puning和对齐问题,这些问题产生了不确定的行为。

编写在工会数组中运行的二进制搜索功能并使用单个迭代的单个比较来定位匹配条目将更加安全,更有效。必须对此数组进行排序,并且可以使用QSort()使用compare128()函数对其进行排序。

以下是一个示例:

#include <stddef.h>

typedef unsigned __int128 u128_t;  // works for gcc, adjust for your compiler

typedef union {
    char c[16];
    u128_t u128;
} mytype;

/* comparison function for qsort and bsearch */
int compare128(const void *p1, const void *p2) {
    const mytype *v1 = p1;
    const mytype *v2 = p2;
    return (v1->u128 > v2->u128) - (v1->u128 < v2->u128);
}

int binarySearch128(const mytype array[], size_t n,
                    const unsigned char key[16])
{
    u128_t keyval;
    memcpy(&keyval, key, sizeof keyval);
    size_t lo = 0, hi = n;
    while (lo < hi) {
        size_t mid = lo + (hi - lo) / 2;
        if (array[mid].u128 < keyval) {
            lo = mid + 1;
        } else {
            hi = mid;
        }
    }
    if (lo < n && array[lo].u128 == keyval) {
        return (int)lo;
    } else {
        return -1;
    }
}

在没有128位整数支持的平台上,您可以使用以下方式:

#include <stdint.h>

typedef union {
    char c[16];
    uint64_t u64[2];
} mytype;

// comparison function for qsort
int compare128(const void *p1, const void *p2) {
    const mytype *v1 = p1;
    const mytype *v2 = p2;
    int cmp = (v1->u64[0] > v2->u64[0]) - (v1->u64[0] < v2->u64[0]);
    return cmp ? cmp : (v1->u64[1] > v2->u64[1]) - (v1->u64[1] < v2->u64[1]);
}

int binarySearch128(const mytype array[], size_t n,
                    const unsigned char key[16])
{
    mytype keyval;
    memcpy(&keyval, key, sizeof keyval);
    size_t lo = 0, hi = n;
    while (lo < hi) {
        size_t mid = lo + (hi - lo) / 2;
        if (array[mid].u64[0] < keyval.u64[0]
        ||  (array[mid].u64[0] == keyval.u64[0] && array[mid].u64[1] < keyval.u64[1]) {
            lo = mid + 1;
        } else {
            hi = mid;
        }
    }
    if (lo < n && array[lo].u64[0] == keyval.u64[0] && array[lo].u64[1] == keyval.u64[1]) {
        return (int)lo;
    } else {
        return -1;  // or 0
    }
}

If numbers are stored in big endian order and the pointers are aligned on 16 byte boundaries, the comparison as unsigned 128 bit values will produce the same result as memcmp. Whether it will be more efficient will depend on the compiler and optimisation settings.

Here is a modified function:

typedef unsigned __int128 u128_t;  // works for gcc, adjust for your compiler

int compare(const void *p1, const void *p2) {
    const u128_t *v1 = p1;
    const u128_t *v2 = p2;
    return (*v1 > *v2) - (*v1 < *v2);
}

The problem is your target system likely uses little endian order (eg: x86 CPUs). If your goal is to find the array in an array of arrays, you could still use this trick as long as the array is sorted using the same comparison.

Using bsearch requires a function pointer that returns a signed value equal to 0 for elements that compare equal, is negative if the element pointed to by p1 is less than the one pointed to by p2 and a positive value otherwise. Another problem with this approach is type punning and alignment issues which produce undefined behavior.

It would be safer and more efficient to write a binary search function that operates on an array of unions and uses a single comparison per iteration to locate the matching entry. This array must be sorted and sorting it can be performed using qsort() with the compare128() function.

Here is an example:

#include <stddef.h>

typedef unsigned __int128 u128_t;  // works for gcc, adjust for your compiler

typedef union {
    char c[16];
    u128_t u128;
} mytype;

/* comparison function for qsort and bsearch */
int compare128(const void *p1, const void *p2) {
    const mytype *v1 = p1;
    const mytype *v2 = p2;
    return (v1->u128 > v2->u128) - (v1->u128 < v2->u128);
}

int binarySearch128(const mytype array[], size_t n,
                    const unsigned char key[16])
{
    u128_t keyval;
    memcpy(&keyval, key, sizeof keyval);
    size_t lo = 0, hi = n;
    while (lo < hi) {
        size_t mid = lo + (hi - lo) / 2;
        if (array[mid].u128 < keyval) {
            lo = mid + 1;
        } else {
            hi = mid;
        }
    }
    if (lo < n && array[lo].u128 == keyval) {
        return (int)lo;
    } else {
        return -1;
    }
}

On platforms without 128-bit integer support, you can use this:

#include <stdint.h>

typedef union {
    char c[16];
    uint64_t u64[2];
} mytype;

// comparison function for qsort
int compare128(const void *p1, const void *p2) {
    const mytype *v1 = p1;
    const mytype *v2 = p2;
    int cmp = (v1->u64[0] > v2->u64[0]) - (v1->u64[0] < v2->u64[0]);
    return cmp ? cmp : (v1->u64[1] > v2->u64[1]) - (v1->u64[1] < v2->u64[1]);
}

int binarySearch128(const mytype array[], size_t n,
                    const unsigned char key[16])
{
    mytype keyval;
    memcpy(&keyval, key, sizeof keyval);
    size_t lo = 0, hi = n;
    while (lo < hi) {
        size_t mid = lo + (hi - lo) / 2;
        if (array[mid].u64[0] < keyval.u64[0]
        ||  (array[mid].u64[0] == keyval.u64[0] && array[mid].u64[1] < keyval.u64[1]) {
            lo = mid + 1;
        } else {
            hi = mid;
        }
    }
    if (lo < n && array[lo].u64[0] == keyval.u64[0] && array[lo].u64[1] == keyval.u64[1]) {
        return (int)lo;
    } else {
        return -1;  // or 0
    }
}

强制A在C中的128位登记册中进行的比较

玩心态 2025-02-06 05:39:46

\ 1 BackReference仅在您的模式中有一个捕获组时才能使用:

(?<=@)(.+?)(?=\r)

如果您不使用捕获组,则应使用$&&&&&&&amp;而不是<<代码> \ 1 作为整个比赛的反向注册。此外,需要逃脱替换字符串中的括号。因此,替换字符串应该是:

amp;", acct.
amp;\);

您可能还需要使用$而不是lookahead (?= \ r),以防最后一行不紧随其后EOL角色。

说了这么多,我个人更喜欢在做正则替代时更加明确/严格,以免弄乱其他线(即误报)。因此,我会选择这样的事情:

查找:(\ bcommand \ .parameters \ .add \(“@)(\ w+)(\ w+)$

替换:\ 1 \ 1 \ 2”,acct。 \ 2 \);

请注意,\ w只能匹配单词字符,这可能是这里所需的行为。如果您认为标识符可能具有其他字符,请随时用角色类替换。

The \1 backreference will only work if you have a capturing group in your pattern:

(?<=@)(.+?)(?=\r)

If you're not using a capturing group, you should use $& instead of \1 as a backreference for the entire match. Additionally, parentheses in the replacement string need to be escaped. So, the replacement string should be:

amp;", acct.
amp;\);

You might also want to use $ instead of the Lookahead (?=\r) in case the last line isn't followed by an EOL character.

Having said all that, I personally prefer to be more explicit/strict when doing regex substitution to avoid messing up other lines (i.e., false positives). So I would go with something like this:

Find: (\bcommand\.Parameters\.Add\("@)(\w+)$

Replace: \1\2", acct.\2\);

Note that \w will only match word characters, which is likely the desired behavior here. Feel free to replace it with a character class if you think your identifiers might have other characters.

与当前行的子字符串相关联的末端

玩心态 2025-02-05 07:29:08

如果您尝试压缩tar.gz文件,则首先需要解压缩GZIP。


import (
    "archive/tar"
    "compress/gzip"
    "fmt"
    "io"
    "log"
    "os"
)

func ExtractTarGz(gzipStream io.Reader) {
    uncompressedStream, err := gzip.NewReader(gzipStream)
    if err != nil {
        log.Fatal("ExtractTarGz: NewReader failed")
    }

    tarReader := tar.NewReader(uncompressedStream)

    for true {
        header, err := tarReader.Next()

        if err == io.EOF {
            break
        }

        if err != nil {
            log.Fatalf("ExtractTarGz: Next() failed: %s", err.Error())
        }

        switch header.Typeflag {
        case tar.TypeDir:
            if err := os.Mkdir(header.Name, 0755); err != nil {
                log.Fatalf("ExtractTarGz: Mkdir() failed: %s", err.Error())
            }
        case tar.TypeReg:
            outFile, err := os.Create(header.Name)
            if err != nil {
                log.Fatalf("ExtractTarGz: Create() failed: %s", err.Error())
            }
            if _, err := io.Copy(outFile, tarReader); err != nil {
                log.Fatalf("ExtractTarGz: Copy() failed: %s", err.Error())
            }
            outFile.Close()

        default:
            log.Fatalf(
                "ExtractTarGz: uknown type: %s in %s",
                header.Typeflag,
                header.Name)
        }

    }
}
func main() {
    r, err := os.Open("./file.tar.gz")
    if err != nil {
        fmt.Println("error")
    }
    ExtractTarGz(r)
}

If you are trying to compress tar.gz file you need first to decompress gzip.


import (
    "archive/tar"
    "compress/gzip"
    "fmt"
    "io"
    "log"
    "os"
)

func ExtractTarGz(gzipStream io.Reader) {
    uncompressedStream, err := gzip.NewReader(gzipStream)
    if err != nil {
        log.Fatal("ExtractTarGz: NewReader failed")
    }

    tarReader := tar.NewReader(uncompressedStream)

    for true {
        header, err := tarReader.Next()

        if err == io.EOF {
            break
        }

        if err != nil {
            log.Fatalf("ExtractTarGz: Next() failed: %s", err.Error())
        }

        switch header.Typeflag {
        case tar.TypeDir:
            if err := os.Mkdir(header.Name, 0755); err != nil {
                log.Fatalf("ExtractTarGz: Mkdir() failed: %s", err.Error())
            }
        case tar.TypeReg:
            outFile, err := os.Create(header.Name)
            if err != nil {
                log.Fatalf("ExtractTarGz: Create() failed: %s", err.Error())
            }
            if _, err := io.Copy(outFile, tarReader); err != nil {
                log.Fatalf("ExtractTarGz: Copy() failed: %s", err.Error())
            }
            outFile.Close()

        default:
            log.Fatalf(
                "ExtractTarGz: uknown type: %s in %s",
                header.Typeflag,
                header.Name)
        }

    }
}
func main() {
    r, err := os.Open("./file.tar.gz")
    if err != nil {
        fmt.Println("error")
    }
    ExtractTarGz(r)
}

如何使用Golang exec.cmd使用TAR命令

玩心态 2025-02-05 06:49:29

您的假设是正确的!

长度大于512的任何内容(假设您使用的是“ Distilbert-Base-Multlingual-capialutal-castialual-castialual-caster”)都可以通过truncation = true来截断。

快速解决方案不会截断和计数示例大于模型的最大输入长度:


train_encoded_no_trunc =  tokenizer(X_train, padding=True, truncation=False, return_tensors="pt")

count=0 

for doc in train_encoded_no_trunc.input_ids:
    if(doc>0).sum()> tokenizer.model_max_length: 
        count+=1
print("number of truncated docs: ",count)

your assumption is correct!

anything with a length larger than 512 ( assuming you are using "distilbert-base-multilingual-cased" ) is truncated by having truncation=True.

A quick solution would be not truncating and counting examples larger than the max input length of the model:


train_encoded_no_trunc =  tokenizer(X_train, padding=True, truncation=False, return_tensors="pt")

count=0 

for doc in train_encoded_no_trunc.input_ids:
    if(doc>0).sum()> tokenizer.model_max_length: 
        count+=1
print("number of truncated docs: ",count)

Hugginface Transferes Bert Tokenizer-找出哪些文档被截断了

玩心态 2025-02-04 16:11:23

要执行您需要的操作,您可以使用clestest() and find()方法来查找与与“全”复选框。然后,您可以使用prop()设置其检查状态以匹配。同样,您可以根据toggleclass()提供布尔值,以根据是否已选中“全部”来添加或删除类。

$(document).on('change', '#select_products_checkbox', function() {  
  $(this).closest('table').find('tbody :checkbox')
    .prop('checked', this.checked)
    .toggleClass('selected', this.checked);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<table class="table table-bordered">
  <thead>
    <tr>
      <td class="col-md-1">
        <input class="form-control" type="checkbox" id="select_products_checkbox">
      </td>
      <td class="col-md-1 text-center">{t}Product ID{/t} - SELECT ALL</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <input name="{$price_list_products_checkbox}[]" value="{$productID}" class="form-control" type="checkbox">
      </td>
      <td class="text-center">
        {$productID}
      </td>
    </tr>
    <tr>
      <td>
        <input name="{$price_list_products_checkbox}[]" value="{$productID}" class="form-control" type="checkbox">
      </td>
      <td class="text-center">
        {$productID}
      </td>
    </tr>
    <tr>
      <td>
        <input name="{$price_list_products_checkbox}[]" value="{$productID}" class="form-control" type="checkbox">
      </td>
      <td class="text-center">
        {$productID}
      </td>
    </tr>
    <tr>
      <td>
        <input name="{$price_list_products_checkbox}[]" value="{$productID}" class="form-control" type="checkbox">
      </td>
      <td class="text-center">
        {$productID}
      </td>
    </tr>
    <tr>
      <td>
        <input name="{$price_list_products_checkbox}[]" value="{$productID}" class="form-control" type="checkbox">
      </td>
      <td class="text-center">
        {$productID}
      </td>
    </tr>
  </tbody>
</table>

To do what you require you can use the closest() and find() methods to find the checkboxes in the tbody of the table related to the 'All' checkbox. Then you can use prop() to set their checked state to match. Similarly you can provide a boolean to toggleClass() to add or remove the class based on whether or not the 'All' was checked.

$(document).on('change', '#select_products_checkbox', function() {  
  $(this).closest('table').find('tbody :checkbox')
    .prop('checked', this.checked)
    .toggleClass('selected', this.checked);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<table class="table table-bordered">
  <thead>
    <tr>
      <td class="col-md-1">
        <input class="form-control" type="checkbox" id="select_products_checkbox">
      </td>
      <td class="col-md-1 text-center">{t}Product ID{/t} - SELECT ALL</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <input name="{$price_list_products_checkbox}[]" value="{$productID}" class="form-control" type="checkbox">
      </td>
      <td class="text-center">
        {$productID}
      </td>
    </tr>
    <tr>
      <td>
        <input name="{$price_list_products_checkbox}[]" value="{$productID}" class="form-control" type="checkbox">
      </td>
      <td class="text-center">
        {$productID}
      </td>
    </tr>
    <tr>
      <td>
        <input name="{$price_list_products_checkbox}[]" value="{$productID}" class="form-control" type="checkbox">
      </td>
      <td class="text-center">
        {$productID}
      </td>
    </tr>
    <tr>
      <td>
        <input name="{$price_list_products_checkbox}[]" value="{$productID}" class="form-control" type="checkbox">
      </td>
      <td class="text-center">
        {$productID}
      </td>
    </tr>
    <tr>
      <td>
        <input name="{$price_list_products_checkbox}[]" value="{$productID}" class="form-control" type="checkbox">
      </td>
      <td class="text-center">
        {$productID}
      </td>
    </tr>
  </tbody>
</table>

jQuery检查表中的所有复选框

玩心态 2025-02-04 15:02:01

Firestore的方法称为Orderby。您可以使用它以降序订购文档。请参阅下面的示例代码:

const postCollection = collection(database, "posts");

const getPost = async () => {
    const data = await getDocs(query(postCollection, orderBy('date', 'desc')));
    const newData = data.docs.map((doc) => ({
        ...doc.data(),
        id: doc.id,
    }));
    
   setPostList(newData);
};

有关更多信息,您可以检查使用云Firestore 订购和限制数据。

Firestore has a method called orderBy. You can use it to order the documents in descending order. See sample code below:

const postCollection = collection(database, "posts");

const getPost = async () => {
    const data = await getDocs(query(postCollection, orderBy('date', 'desc')));
    const newData = data.docs.map((doc) => ({
        ...doc.data(),
        id: doc.id,
    }));
    
   setPostList(newData);
};

For more information, you may check Order and limit data with Cloud Firestore.

如何按REACT中的日期按firebase文档进行排序?

玩心态 2025-02-04 12:37:45

对我来说,这两个参数有助于:

keyboardShouldPersistTaps={'always'}
automaticallyAdjustKeyboardInsets={true}

我的整个组件看起来像:
(我使用 react-native-keyboard-saware-scroll-view 软件包用于键盘隐藏组件)

 <KeyboardAwareScrollView
     showsVerticalScrollIndicator={false}
     showsHorizontalScrollIndicator={false}
     style={styles.scrollContainer}
     keyboardShouldPersistTaps={'always'}
     automaticallyAdjustKeyboardInsets={true}>
    ... your code ...
    </KeyboardAwareScrollView>

For me this two parameter helped:

keyboardShouldPersistTaps={'always'}
automaticallyAdjustKeyboardInsets={true}

My whole component is look like:
(I use react-native-keyboard-aware-scroll-view package for aware keyboard hide components)

 <KeyboardAwareScrollView
     showsVerticalScrollIndicator={false}
     showsHorizontalScrollIndicator={false}
     style={styles.scrollContainer}
     keyboardShouldPersistTaps={'always'}
     automaticallyAdjustKeyboardInsets={true}>
    ... your code ...
    </KeyboardAwareScrollView>

屏幕跳到React Antial中的顶部,然后单击TextInput

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

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