小编Eмα*_*мαd的帖子

为什么在 setTimeout 中更改 State 会导致无限循环

我有一个功能组件,我想更改 a 内的 State setTimeout,但我不知道为什么它会导致组件处于无限循环中!

这是我的功能组件

import { useState } from "react";

function Card() {
  const [booksState, setBooks] = useState({
    books: [
      { name: "Harry", id: 1 },
      { name: "Potter", id: 2 },
      { name: "John", id: 3 },
    ],
  });

  console.log("test");

  setTimeout(() => {
    let newBooks = [
      { name: "test1", id: 4 },
      { name: "test2", id: 5 },
      { name: "test3", id: 6 },
    ];

    setBooks({
      books: [...booksState.books, ...newBooks],
    });
  }, …
Run Code Online (Sandbox Code Playgroud)

reactjs

5
推荐指数
1
解决办法
1726
查看次数

使用AJAX显示Laravel验证错误

我有一个FormLaravel该提交与Ajax.every东西效果很好,但问题是,我不能在HTML渲染验证的错误.
(我想<ul><li>在我的HTML中显示错误)

这是我的Ajax请求:

 $(document).ready(function () {
        $("#submit").click(function (xhr) {
            xhr.preventDefault(),
                $.ajax({
                    type: "POST",
                    contentType: "charset=utf-8",
                    dataType: 'json',
                    url: "{{route('messages.store')}}",
                    headers: {
                        "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
                    },
                    data: {
                        name: $("#name").val(),
                        email: $("#email").val(),
                        phone: $("#company").val(),
                        subject: $("#subject").val(),
                        message: $("#message").val()
                    },
                    success: function () {
                        alert('True');
                    },
                    error: function (xhr) {
                        console.log((xhr.responseJSON.errors));
                    }
                }, "json")
        })
    });
Run Code Online (Sandbox Code Playgroud)

控制台日志:

截图

谢谢你的帮助.

ajax jquery laravel

3
推荐指数
1
解决办法
5236
查看次数

如何更改PagerTabStrip的字体

我正在使用带PagerTabStrip的ViewPager,我需要设置自定义字体(typeface),但是.setTypeFacePagerTabStrip 没有任何功能!

这是我的XML代码:

 <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/viewPager"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <android.support.v4.view.PagerTabStrip
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pagerTabStrip"
        android:layout_gravity="top"
        android:background="#FF0000"
        android:textColor="#FFFFFF" />

</android.support.v4.view.ViewPager>
Run Code Online (Sandbox Code Playgroud)

根据此链接,我找到了可以解决我的问题的解决方案。

获取PagerTabStrip的子视图,并检查它是否是TextView的实例。如果是,请设置字体:

for (int i = 0; i < pagerTabStrip.getChildCount(); ++i) {
View nextChild = pagerTabStrip.getChildAt(i);
if (nextChild instanceof TextView) {
   TextView textViewToConvert = (TextView) nextChild;
   textViewToConvert.setTypeface(PUT_TYPEFACE_HERE)
}
}
Run Code Online (Sandbox Code Playgroud)

但是我不明白这意味着什么。

我的布局是:

图片

我想将标题标签更改为另一种字体样式,如下所示:

图片

android android-viewpager android-tabstrip

2
推荐指数
1
解决办法
3375
查看次数