我一向站在原地

文章 评论 浏览 29

我一向站在原地 2025-02-21 02:10:38

您的方法具有类型供应商< integer>的一个参数,因此您有三个选择将作为参数传递给此方法的选择(这个想法是通过一个实现功能接口供应商的类的实例):

  • < p> lambda表达式

      public void callfunc(){
        fsupplier(() - &gt; integer.valueof(1));
    }
     
  • 方法参考

      public void callfunc(){
         fsupplier(this :: myfunc);
     }
     
  • 匿名内部类

      public void callfunc(){
         fsupplier(新供应商&lt; integer&gt;(){
    
             @Override
             公共整数get(){
                 返回integer.valueof(1);
             }
         }); 
     }
     

Your method have one parameter of type Supplier<Integer> so you have three choices to pass as argument to this method (the idea is to pass an instance of a class who implements the functional interface Supplier):

  • A lambda expression

    public void callFunc() {
        fSupplier(()->Integer.valueOf(1));
    }
    
  • A method reference

    public void callFunc() {
         fSupplier(this::myfunc);
     }
    
  • An anonymous inner class

     public void callFunc(){
         fSupplier(new Supplier<Integer>() {
    
             @Override
             public Integer get() {
                 return Integer.valueOf(1);
             }
         }); 
     }
    

供应商的Java功能接口&lt; t&gt;无法编译非lambda

我一向站在原地 2025-02-20 19:15:34

我有一个稍微不同的解决方案 -

  • 简化fun_insert函数 sprintf 。
  • fun_insertj)中添加了一个附加参数,以便我们可以摆脱storage_med_pt1
  • 而不是嵌套<代码> 循环我使用了嵌套sapply。它以同样的方式工作。
fun_insert <- function(org, i, j, stor) sprintf('%s ~ a%i%i*%s', org, i, j, stor)

#For one value
fun_insert(original_m[1], 1, 1, storage_mod_xm_all[1])
#[1] "BODYSHAME ~ a11*FEAROFSELFCOMPASSION"

#For all of them
c(t(sapply(seq_along(original_m), function(x) {
  sapply(seq_along(storage_mod_xm_all), function(y) {
    fun_insert(original_m[x], x, y, storage_mod_xm_all[y])
  })
})))

#[1] "BODYSHAME ~ a11*FEAROFSELFCOMPASSION" "WBIS_M ~ a21*FEAROFSELFCOMPASSION" 
#[3] "BODYSHAME ~ a12*SBOSS"                "WBIS_M ~ a22*SBOSS"        

I have a slightly different solution -

  • Simplified fun_insert function to a one-liner sprintf.
  • Added an additional argument in fun_insert (j) so that we can get rid of storage_med_pt1.
  • Instead of nested for loop I have used nested sapply. It works the same way.
fun_insert <- function(org, i, j, stor) sprintf('%s ~ a%i%i*%s', org, i, j, stor)

#For one value
fun_insert(original_m[1], 1, 1, storage_mod_xm_all[1])
#[1] "BODYSHAME ~ a11*FEAROFSELFCOMPASSION"

#For all of them
c(t(sapply(seq_along(original_m), function(x) {
  sapply(seq_along(storage_mod_xm_all), function(y) {
    fun_insert(original_m[x], x, y, storage_mod_xm_all[y])
  })
})))

#[1] "BODYSHAME ~ a11*FEAROFSELFCOMPASSION" "WBIS_M ~ a21*FEAROFSELFCOMPASSION" 
#[3] "BODYSHAME ~ a12*SBOSS"                "WBIS_M ~ a22*SBOSS"        

嵌套以循环:索引在r中的问题

我一向站在原地 2025-02-20 18:53:46

一种做到这一点的方法是,在情况下使用情况和使用常规订购的情况下使用案例对项目的订购优先级。这样的优先级将在字母内进行,然后是数字,然后在相应类别中订购

select a.*
  from t a
order by case when translate(x,'0123456789','         ')<>x then 1 else 0 end
         ,x  

+--------+
| output |
+--------+
| AA     |
| AB     |
| AC     |
| AZ     |
| 00     |
| 01     |
| 02     |
| 4      |
+--------+

https://dbfiddle.uk/?rdbms=oracle_11.2&; fiddle = dff7E6805F1B59501D59CB91194CF1A0

One way to do this would be to prioritize the ordering of items by alphabets using case when condition and after that to use the regular ordering. This way the priority sort would be on alphabets then numbers, followed by ordering within the respective categories

Eg:

select a.*
  from t a
order by case when translate(x,'0123456789','         ')<>x then 1 else 0 end
         ,x  

+--------+
| output |
+--------+
| AA     |
| AB     |
| AC     |
| AZ     |
| 00     |
| 01     |
| 02     |
| 4      |
+--------+

https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=dff7e6805f1b59501d59cb91194cf1a0

甲骨文 - 首先按字母排序然后数字

我一向站在原地 2025-02-20 12:29:43

就我而言,它无法发现仅仅因为我的当地就有它而在远程环境中都不存在。
因此,我不得不在本地机器上删除宝石library/caches/jetbrains/rubymine2022.3/ruby_stubs/256935961/home/home/ubuntu/.rvm/gems/ruby-3.1.1.4/ruby-debug-debug-iide -3.0.0.beta.6.1/,用于调试再次工作。

In my case, It was not able to detect that gem wasn't present in the remote environment just because my local had it.
So, I had to delete gems on my local machine Library/Caches/JetBrains/RubyMine2022.3/ruby_stubs/256935961/home/ubuntu/.rvm/gems/ruby-3.1.4/gems/ruby-debug-ide-3.0.0.beta.6.1/ for the debugging to work again.

如何迫使红宝石重新安装它用于在偏远环境中调试的宝石

我一向站在原地 2025-02-20 10:44:40

我不太确定您想如何将员工添加到数组中,所以我在这里做了一些假设。

该代码将递归地遍历数组的所有元素,直到找到与父ID匹配的元素。此时,它将指定的项目添加到该“父”的_Children属性。

注意:如果您喜欢通过参考传递数组,则可以简化这一点。对于此示例,我已经设置了它,以便它不会编辑原始数组(除非您覆盖变量)。

function addChild(array $main, array $item, $parent_id) {
    foreach ($main as $key => $element) {
        if ($parent_id === $element["id"]) {
            // create _children element if not exist
            if (!isset($element["_children"])) {
                $element["_children"] = [];
            }

            $element["_children"][] = $item;

            // specify $main[$key] here so that the changes stick
            // outside this foreach loop
            $main[$key] = $element;


            // item added - break the loop
            break;
        }

        // continue to check others if they have children
        if (isset($element["_children"])) {
            $element["_children"] = addChild($element["_children"], $item, $parent_id);

            // specify $main[$key] here so that the changes stick
            // outside this foreach loop
            $main[$key] = $element;
        }
    }

    return $main;
}

$employee = [
    "id"        => 99,
    "name"      => "Test Employee",
    "parent_id" => 4,
];

$new_rows = addChild($rows, $employee, $employee["parent_id"]);

注意:这使用$ parent_id === $ element [“ id”]的严格比较,意思。您可以将这些值转换为相同的格式,也可以更改为非图案比较==

I'm not too sure how you want to add employees to the array so I've made some assumptions here.

This code will traverse through all elements of an array recursively until it finds an element that matches the parent ID. At this point, it will add the specified item to the _children property of that "parent".

NOTE: this can be simplified if you preferred passing the array by reference. For this example I've set it up so that it doesn't edit the original array (unless of course you overwrite the variable).

function addChild(array $main, array $item, $parent_id) {
    foreach ($main as $key => $element) {
        if ($parent_id === $element["id"]) {
            // create _children element if not exist
            if (!isset($element["_children"])) {
                $element["_children"] = [];
            }

            $element["_children"][] = $item;

            // specify $main[$key] here so that the changes stick
            // outside this foreach loop
            $main[$key] = $element;


            // item added - break the loop
            break;
        }

        // continue to check others if they have children
        if (isset($element["_children"])) {
            $element["_children"] = addChild($element["_children"], $item, $parent_id);

            // specify $main[$key] here so that the changes stick
            // outside this foreach loop
            $main[$key] = $element;
        }
    }

    return $main;
}

$employee = [
    "id"        => 99,
    "name"      => "Test Employee",
    "parent_id" => 4,
];

$new_rows = addChild($rows, $employee, $employee["parent_id"]);

NOTE: this uses a strict comparison for $parent_id === $element["id"] meaning an int won't match a string. You can either convert these values into the same format or change to a non-strict compare ==.

在层次结构阵列上进行遍历的最佳方法

我一向站在原地 2025-02-20 08:23:13

您可以使用以下类似的方式使用运行计数(假设这是您正在谈论的MS SQL)

SELECT ROW_NUMBER() over(partition by [LineId] order by [LineId]) as DocId,
      [LineId],
      [Price]
  FROM [StackOverflow].[dbo].[RunningCount] order by [LineId]

You could use running counts using something like below (assuming this is MS SQL you are talking about)

SELECT ROW_NUMBER() over(partition by [LineId] order by [LineId]) as DocId,
      [LineId],
      [Price]
  FROM [StackOverflow].[dbo].[RunningCount] order by [LineId]

SQL- lineId =&#x27; 01&#x27;然后newid否则ID

我一向站在原地 2025-02-20 06:56:05

好的,因此您在代码中使用aria-label的预期用法有些混乱。

您的代码:

<header class="c-site-header">
    <nav id="aria-label"> 
        <a class="main site links" href="#">About Me</a> 
        <a class="main site links" href="my project">My Projects</a> 
        <a class="main site links" href="contact me">Contact Me</a> 
    </nav>
    <h1>Welcome To My Page</h1>
</header>

aria-label本身是位于HTML元素(不是ID)上的属性,仅在看不到元素的文本标签的情况下才能使用。

考虑此示例:
您有一个“关闭”图标的SVG。浏览器只能看到您拥有SVG,无法确定其内容或目的。对于那些可以看到它的人来说,这可能很明显,但是对于那些依靠辅助技术的损害的人来说,您需要提供其他信息。

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 371.23 371.23" style="enable-background:new 0 0 371.23 371.23"...>

您添加的其他信息可以通过多种方式完成,其中之一是aria-label

<svg xmlns="http://www.w3.org/2000/svg" aria-label="Close the mobile menu" viewBox="0 0 371.23 371.23" style="enable-background:new 0 0 371.23 371.23"...>

现在辅助技术可以使用标签来解释此元素的作用。

在您的上下文中,您使用的是HTML5标签,这些标签暗示了详细信息,您无需添加其他ARIA信息。

有关ARIA的更多详细信息,它是用法和约束,我建议 mdn的文档。

OK, so your intended usage of aria-label in your code (see below) is a bit muddled.

Your code:

<header class="c-site-header">
    <nav id="aria-label"> 
        <a class="main site links" href="#">About Me</a> 
        <a class="main site links" href="my project">My Projects</a> 
        <a class="main site links" href="contact me">Contact Me</a> 
    </nav>
    <h1>Welcome To My Page</h1>
</header>

aria-label, is itself a property which sits on HTML elements (not as an ID) and should only be used where text that could label an element is not visible.

Consider this example:
You have an SVG of a 'close' icon. The browser can only see that you have an SVG, it cannot determine its contents or purpose. To those who can see it, it might be readily obvious what it is, but for those with an impairment who rely on assistive technology, you need to provide additional information.

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 371.23 371.23" style="enable-background:new 0 0 371.23 371.23"...>

The additional information you add can be done in many ways, one of which is the aria-label:

<svg xmlns="http://www.w3.org/2000/svg" aria-label="Close the mobile menu" viewBox="0 0 371.23 371.23" style="enable-background:new 0 0 371.23 371.23"...>

Now assistive technologies can use the label to explain what this element does.

In your context, you are using HTML5 tags which have implied details and you have no need to add additional aria information.

For more details about aria, it's usage and constraints, I recommend MDN's documentation.

步骤问题 - 有一个带有主站点链接的杂志标签的导航元素

我一向站在原地 2025-02-19 23:47:30

该语句不是完全正确的,因为:

The statement is not entirely true because:

  • "A heap of ???? keys is an array ????": A heap is not necessarily implemented using an array. This should be rephrased.

  • "to balanced binary tree": this is only true for a binary heap. There are d-ary heaps.

  • "equivalent" means the statement works in both directions, but a balanced binary tree is not guaranteed to correspond to a binary heap.

I would suggest a statement like this:

A binary heap of ???? keys -- as can be implemented by an array ???? of size ???? -- represents a balanced binary tree, whose leaves’ depths differ by at most 1 and that depth is Θ(log⁡????).

This is a true statement, because a binary heap is by definition a complete binary tree, as stated in Wikipedia:

Shape property: a binary heap is a complete binary tree; that is, all levels of the tree, except possibly the last one (deepest) are fully filled, and, if the last level of the tree is not complete, the nodes of that level are filled from left to right.

This property already says the binary heap is a binary tree with its leaves at the bottom level, and possibly some at the level above it. That means the maximum difference in depths of the leaves is 1.

Given a binary heap with ???? keys, the first (root) level will have 1 key, the second level will have 2 keys, the third level will have 4 keys,... etc, each time doubling, until all keys are distributed, and so the last level may have a number of nodes that is not a power of 2.

If we number the keys in level order, starting with 1, then the left-most node at the second level will have number 2, the left-most node at the third level will have number 4,... etc, each time the next power of 2, so that the left most node at level ???? (starting from zero) has number 2????. The left most node at the bottom level will have a number 2????, such that ⁡????/2 < 2???? ≤ ⁡????

The depth of that node on the bottom level is thus ????, which (given the above range for 2????) is O(log????).

Note that the fact that the binary heap can be nicely represented as an array ????, is not really relevant, as the property of complete binary tree is already present in the definition of a binary heap.

如何证明&#x1d45b的堆;键是一个数组&#x1d434;等效于平衡的二进制树

我一向站在原地 2025-02-19 21:21:33

首先,如果打印出c,则获得eq(x(t),(f*t/880 + cos(440*t)/440)*sin(440* t))。要绘制,您需要通过c.rhs获得此方程的右手侧。

另请注意,(再次,打印)您在c.rhs中仍然具有符号f,我们应该用您的数值替换(我将手动输入替换为<<代码> W = 440 )。这样就可以使我们c.rhs.subs(f,w)

然后,lambdify正确执行,为我们提供了一个纯粹的数值值,而不是符号值,我们可以通过plt.plot(n,y)来绘制这些值。

总而言之,

[nav] In [29]: from sympy import *
          ...: import sympy as sp
          ...: 
          ...: from sympy.abc import *
          ...: import numpy as np
          ...: 
          ...: import matplotlib.pyplot as plt
          ...: x=sp.Function('x')
          ...: 
          ...: t=symbols('t')
          ...: w=440
          ...: 
          ...: eq= sp. Eq(x(t).diff(t,2)+w**2*x(t)-f*sp .cos(w*t),0)
          ...: c= sp. dsolve(eq,x(t),ics={x(0):0,x(t).diff(t).subs(t,0):sp .cos(w*t)})
          ...: 
          ...: d= lambdify(t,c.rhs.subs(f, w),modules='numpy')
          ...: n= np. arange (0,10,1)
          ...: 
          ...: 
          ...: y=d(n)
          ...: plt.plot(n, y)
          ...: plt.show()

First up, if you print out your c, you get Eq(x(t), (f*t/880 + cos(440*t)/440)*sin(440*t)). For plotting, you need to get the right hand side of this equation via c.rhs.

Also note that (again, printing) you still have the symbolic f in your c.rhs, which we should replace with your numerical value (I replaced the manual input with w = 440). So that gets us c.rhs.subs(f, w).

Then lambdify executes correctly, giving us an array of purely numerical values, rather than symbolic ones, which we can plot via plt.plot(n, y).

All in all,

[nav] In [29]: from sympy import *
          ...: import sympy as sp
          ...: 
          ...: from sympy.abc import *
          ...: import numpy as np
          ...: 
          ...: import matplotlib.pyplot as plt
          ...: x=sp.Function('x')
          ...: 
          ...: t=symbols('t')
          ...: w=440
          ...: 
          ...: eq= sp. Eq(x(t).diff(t,2)+w**2*x(t)-f*sp .cos(w*t),0)
          ...: c= sp. dsolve(eq,x(t),ics={x(0):0,x(t).diff(t).subs(t,0):sp .cos(w*t)})
          ...: 
          ...: d= lambdify(t,c.rhs.subs(f, w),modules='numpy')
          ...: n= np. arange (0,10,1)
          ...: 
          ...: 
          ...: y=d(n)
          ...: plt.plot(n, y)
          ...: plt.show()

使用Sympy绘制微分方程的解决方案

我一向站在原地 2025-02-19 19:54:50

另一个线程可以调用pthread_cancel在这种情况下waitforsingleobject将立即返回,并且在您的简单睡眠时将杀死该线程在未知的时间内。

为什么他们在睡觉(0)之前调用pthread_testcancel,如果(s-&gt; evstart),我不知道。也许您应该直接询问作者是否在乎。我认为他们在那里是有原因的...

Another thread can call pthread_cancel in which case WaitForSingleObject will return immediately and the thread will be killed while your simple Sleep would keep a now pointless thread around for an unknown amount of time.

Why they are calling pthread_testcancel before Sleep(0) and if (s->evStart), I don't know. Maybe you should ask the authors directly if you care that much about it. I assume they are there for a reason...

为什么在winpthreads的'纳米leep”实现中多次调用`pthread_testcancel`?

我一向站在原地 2025-02-19 13:01:38

我从

Quote iCyjoseph

嗨,

是的,所以将这两个错误组合在一起。

因为客户在第一帧上需要看到相同的html
服务器发送了,以放置事件听众并放置
兄弟姐妹和孩子正确,如果有错误的话
做完,React记录一个错误。这已经发生了
反应17 afaik。

问题2与新的渲染根开始了
作为渲染错误,这是不友好的并发功能,因此
水合失败了,它将整个东西扔到窗外。

至少这就是我解释第二个错误的方式。很多人
被忽略的错误数字1,在整个2年中,React 17均已发布,
并不是说您做到了,而是很多使用的图书馆,而其他图书馆只是
忽略了他们。可能的工作

时间和随机性是最常见产生的两件事
这个。

我会这样攻击这个问题:

  1. 让服务器渲染时间,但以UTC格式
  2. 可选,放置将其隐藏的CSS,但仍存在于布局(不显示)
  3. 从客户端,更新到正确的时区,也使时间可见
 导入{cssproperties,useffect,usestate}来自“ react”;
导入{example}来自“ ../ Components/example”;

const timeDisplay =({time}:{time:number})=&gt; {
  const [currenttime,setCurrenttime] = usestate((()=&gt; {
    const hour =(“ 0” + new Date(Time * 1000).getUtchours())。切片(-2);
    const分钟=(“ 0” + new Date(Time * 1000).getutcminutes())。切片(-2);

    返回`$ {hour}:$ {分钟} utc`;
  });

  useeffect(()=&gt; {
    setCurrenttime(()=&gt; {
      const hour =(“ 0” + new Date(Time * 1000).gethours())。切片(-2);
      const分钟=(“ 0” + new Date(Time * 1000).getMinutes())。切片(-2);

      返回`$ {hour}:$ {分钟}`;
    });
  }, [时间]);

  //可选地使此内容占用空间,但保持无形,以避免布局变化
  //最好使用CSS课程
  const样式:cssproperties = {
    可见性:currenttime.ixludes(“ UTC”)? “隐藏”:“可见”,
  };

  返回 (
    &lt; Actip&gt;
      &lt; p style = {style}&gt; {currenttime}&lt;/p&gt;
    &lt;/apress&gt;
  );
};
 

我建议还会在DateTimeFormat API中进行混合,
https://developer.mozilla.org/en-us/docs/web/javascript/reference/reference/global_objects/intl/datementl/datement emptimeformat
可以照顾您的时区:

  const date = new Date(date.utc(2012,11,20,3,0,0,0,200));

选项= {
  小时:“数字”,分钟:“数字”,第二:“数字”, 
  TimeZoneName:“ Short” 
};

console.log(new Intl.dateTimeFormat('sv-se',options).format(date));
 

如果我将上述运行到 repl ,我得到3:00:00 am am am am am a am这是
您的服务器发送的内容),但是如果我在获得的浏览器上运行它,
4:00:00 CET。

您页面的源代码包含服务器所看到的时间。

由于用户从不同的时区到达您,您必须
说明您显示UTC的框架,然后显示时间
用户时区。将其与CSS可见性结合好,
因为您可以避免布局变化等等,所以时间将花在
位置,但看不到。

机器人,爬行者仍然会看到时间,对于JS禁用的用户,
您可以添加一个使日期再次可见的标签。

I got an answer from GitHub discussions on next.js, I will paste it here for anyone facing the same problem as me:

Quote icyJoseph:

Hi,

Yeah so this two errors are combined.

Because the client, on the first frame, needs to see the same HTML as
the server sent over, in order to place event listeners and place
siblings and children correctly, if there's an error while this is
being done, React logs an error. This has happened all the way back to
React 17 AFAIK.

Problem number 2 kicks in with the new rendering root, which sees this
as a rendering error, which is unfriendly to concurrent features, so
hydration fails and it throws the entire thing out the window.

At least that's how I interpret the second error. Lots of people just
ignored error number 1, during the entire 2 years React 17 was out,
not saying you did, but many use libraries that did, and others just
ignored them. Possible work around

Time and randomness are two of the things that most commonly produce
this.

I would attack this problem like this:

  1. Let the server render the time, but in UTC format
  2. Optionally, put CSS that makes this hidden, but still present on the layout (not display none)
  3. From the client, update to the correct time zone, also make the time visible
import { CSSProperties, useEffect, useState } from "react";
import { Example } from "../components/Example";

const TimeDisplay = ({ time }: { time: number }) => {
  const [currentTime, setCurrentTime] = useState(() => {
    const hour = ("0" + new Date(time * 1000).getUTCHours()).slice(-2);
    const minutes = ("0" + new Date(time * 1000).getUTCMinutes()).slice(-2);

    return `${hour}:${minutes} UTC`;
  });

  useEffect(() => {
    setCurrentTime(() => {
      const hour = ("0" + new Date(time * 1000).getHours()).slice(-2);
      const minutes = ("0" + new Date(time * 1000).getMinutes()).slice(-2);

      return `${hour}:${minutes}`;
    });
  }, [time]);

  // optionally make this content take space, but remain invisible, to avoid layout shifts
  // it's better to use a CSS class instead
  const style: CSSProperties = {
    visibility: currentTime.includes("UTC") ? "hidden" : "visible",
  };

  return (
    <article>
      <p style={style}>{currentTime}</p>
    </article>
  );
};

I'd recommend also mixing in the DateTimeFormat API,
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat,
which can take care of showing the time zone for you:

const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0, 200));

options = {
  hour: 'numeric', minute: 'numeric', second: 'numeric', 
  timeZoneName: 'short' 
};

console.log(new Intl.DateTimeFormat('sv-SE', options).format(date));

If I run the above on a repl, I get 3:00:00 AM UTC (this would be
what your server sends), but if I run it on the browsers I get,
4:00:00 CET.

The source code of you page contains the time seen by the server.

Since users arrive to you from different time zones, you have to
account for a frame where you show UTC, and then you show the time for
the users time zone. Combining this with CSS visibility is good,
because you can avoid layout shifts and such, the time will take its
place, but it won't be visible.

Robots, crawlers still see the time, and for users with JS disabled,
you could add a tag that makes the date visible again.

NextJS水合错误(文本内容与服务器渲染的HTML不匹配。)

我一向站在原地 2025-02-18 21:26:30

我假设您的意思是您发现的第一个数字是0(否则它应该返回“ J02”的false,因为02是第一个数字)

x = "J02"
def not_starting_zero(m):
    for char in m:
        if char.isdigit() == True:
            if char == "0":
                return True
            else:
                return False
    return False
not_starting_zero(x)

这项工作起作用,因为一旦在函数中执行返回后,该函数的其余部分就不会执行。希望这能解决您的怀疑。

您不需要制作数字数字,因为您只需要检查字符串中的第一个数字即可。如果它的0返回true否则返回false。

I'm assuming you mean the first digit you find is 0 (because otherwise it should return False for "J02" because 02 is the first number)

x = "J02"
def not_starting_zero(m):
    for char in m:
        if char.isdigit() == True:
            if char == "0":
                return True
            else:
                return False
    return False
not_starting_zero(x)

This works because once return is executed in a function the rest of the function is not executed. Hope this clears up your doubt.

You don't need to make an array of the digits because you only need to check the first digit in the string; if its a 0 then return True else return False.

如何使用功能来识别字母数字字符串中的第一个数字是否为零?

我一向站在原地 2025-02-17 20:14:38

尝试使用级联参数将多个组件一起“将多个组件连接在一起,并且两种方式绑定并不总是做事的最佳方法,尤其是一个页面中子组件的子组件(看来您正在尝试从显示的信息中执行在问题中)。

使用标准事件模型有一种替代方法。

我的债务人

public class Debtor
{
    public Guid Id { get; set; }    
    public string? Name { get; set; }
}

a级债务人查看服务:

public class DebtorViewService
{
    public Debtor Record { get; private set; } = default!;

    public event EventHandler<Debtor>? DebtorChanged;

    public DebtorViewService()
    {
        // Get and assign the Debtor Store DI service
    }

    public async ValueTask GetCurrentDebtor(Guid debtor)
    {
        // Emulate getting the Debtor from the Debtor Service
        await Task.Delay(1000);
        this.Record = new Debtor() { Name=$"Fred {DateTime.Now.ToLongTimeString()}", Id = Guid.NewGuid()};
        this.DebtorChanged?.Invoke(this, this.Record); 
    }
}

在这样的服务中注册:

builder.Services.AddScoped<DebtorViewService>();

获得债务人的组件:

getDebtor.razor.razor

@inject DebtorViewService Service

<div class="m-2 p-3 bg-dark text-white">
    <h5>GetDebtor Component</h5>
    <div>
        <button class="btn btn-secondary" @onclick=this.GetCurrentDebtor>Get Debtor</button>
    </div>
</div>
@code {
    private async Task GetCurrentDebtor()
        => await Service.GetCurrentDebtor(Guid.Empty);
}

是向债务人展示的组件:

showdebtor。 Razor

@inject DebtorViewService Service
@implements IDisposable

<div class="m-2 p-3 bg-info">
    <h5>ShowDebtor Component</h5>
    @if (this.Service.Record is not null)
    {
        <div>
            Id : @this.Service.Record.Id
        </div>
        <div>
            Name : @this.Service.Record.Name
        </div>
    }
</div>

@code {
    protected override void OnInitialized()
        => this.Service.DebtorChanged += this.OnDebtorChanged;

    private void OnDebtorChanged(object? sender, Debtor value)
    => this.InvokeAsync(this.StateHasChanged);

    public void Dispose()
        => this.Service.DebtorChanged -= this.OnDebtorChanged;
}

和一个演示页面:

@page "/"
<PageTitle>Index</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

<GetDebtor />

<ShowDebtor />

<SurveyPrompt Title="How is Blazor working for you?" />

@code{
}

数据和更改事件现在以一个每个人都可以访问的单个共享(范围)DI服务实例。

您应该能够根据此代码构建组件。

Trying to "wire" multiple components together using cascading parameters and two way binding isn't always the best way to do things, particularly sub-component to sub-component within a page (which it appears you are trying to do from the information shown in the question).

There is an alternative approach using the standard event model.

My Debtor class

public class Debtor
{
    public Guid Id { get; set; }    
    public string? Name { get; set; }
}

A Debtor view service:

public class DebtorViewService
{
    public Debtor Record { get; private set; } = default!;

    public event EventHandler<Debtor>? DebtorChanged;

    public DebtorViewService()
    {
        // Get and assign the Debtor Store DI service
    }

    public async ValueTask GetCurrentDebtor(Guid debtor)
    {
        // Emulate getting the Debtor from the Debtor Service
        await Task.Delay(1000);
        this.Record = new Debtor() { Name=
quot;Fred {DateTime.Now.ToLongTimeString()}", Id = Guid.NewGuid()};
        this.DebtorChanged?.Invoke(this, this.Record); 
    }
}

Registered in services like this:

builder.Services.AddScoped<DebtorViewService>();

A Component to get the Debtor:

GetDebtor.razor

@inject DebtorViewService Service

<div class="m-2 p-3 bg-dark text-white">
    <h5>GetDebtor Component</h5>
    <div>
        <button class="btn btn-secondary" @onclick=this.GetCurrentDebtor>Get Debtor</button>
    </div>
</div>
@code {
    private async Task GetCurrentDebtor()
        => await Service.GetCurrentDebtor(Guid.Empty);
}

A component to show the Debtor:

ShowDebtor.razor

@inject DebtorViewService Service
@implements IDisposable

<div class="m-2 p-3 bg-info">
    <h5>ShowDebtor Component</h5>
    @if (this.Service.Record is not null)
    {
        <div>
            Id : @this.Service.Record.Id
        </div>
        <div>
            Name : @this.Service.Record.Name
        </div>
    }
</div>

@code {
    protected override void OnInitialized()
        => this.Service.DebtorChanged += this.OnDebtorChanged;

    private void OnDebtorChanged(object? sender, Debtor value)
    => this.InvokeAsync(this.StateHasChanged);

    public void Dispose()
        => this.Service.DebtorChanged -= this.OnDebtorChanged;
}

And a demo page:

@page "/"
<PageTitle>Index</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

<GetDebtor />

<ShowDebtor />

<SurveyPrompt Title="How is Blazor working for you?" />

@code{
}

The data and the change event is now in a single shared (Scoped) DI service instance that everyone has access to.

You should be able to build your components based on this code.

使用级联参数用于传递值的问题

我一向站在原地 2025-02-17 12:34:09

有时,复选框无法直接交互。您可能需要单击复选框旁边的标签/文本。

或者可能是您必须等到元素可单击,因为您的循环运行。

Sometimes, the checkbox is not directly interactable. You may have to click on the label/text next to the checkbox.

or May be you have to wait till the element is clickable since your are running in a loop.

如何在使用硒时避免元素ClickInterceptedException?

我一向站在原地 2025-02-17 10:11:27

谢谢@windowsill的帮助。

export interface FinancialData {
handleViewData: () => void;
symbol: string;
name: string;
stockExchange: string;
exchangeShortName: string;
currency: string;
}

export const useGetFinancialDataKey = 'get-financial-data';

const useGetFinancialData = (
options: UseQueryOptions<FinancialData[], string> = {}
 ): UseQueryResult<FinancialData[], string> => 
 useQuery<FinancialData[], string>(
  useGetFinancialDataKey,
 async () =>
(await axiosInstance.get<FinancialData[]>('https://financialmodelingprep.com/api/v3/search?query=AA&limit=10&exchange=NASDAQ&apikey=blahblah'
))
.data,
options

);


 export default useGetFinancialData;

thank you @windowsill for helping.

export interface FinancialData {
handleViewData: () => void;
symbol: string;
name: string;
stockExchange: string;
exchangeShortName: string;
currency: string;
}

export const useGetFinancialDataKey = 'get-financial-data';

const useGetFinancialData = (
options: UseQueryOptions<FinancialData[], string> = {}
 ): UseQueryResult<FinancialData[], string> => 
 useQuery<FinancialData[], string>(
  useGetFinancialDataKey,
 async () =>
(await axiosInstance.get<FinancialData[]>('https://financialmodelingprep.com/api/v3/search?query=AA&limit=10&exchange=NASDAQ&apikey=blahblah'
))
.data,
options

);


 export default useGetFinancialData;

即使get在起作用,也没有显示数据

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

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