event-id 相关问题


完整日历:使用 IF 语句为事件着色

我有一个基于站点管理员打开的票证的日历。我们有四种类型的门票: 待办的 进行中 完成的 取消 这是我有日历的 div: 我有一个基于站点管理员打开的票证的日历。我们有四种类型的门票: 待定 进行中 完成了 取消 这是我有日历的div: <div class="col-lg-6 col-md-10 col-sm-11"> <div class="card"> <div class="card-header" data-background-color="blue"> <h4 class="title">Calendario</h4> </div> <br> <section class="content"> <?php $events = TicketData::getEvents(); foreach($events as $event){ $thejson[] = array("title"=>$event->title,"url"=>"./?view=editticket&id=".$event->id,"start"=>$event->date_at."T".$event->time_at); } // print_r(json_encode($thejson)); ?> <script> $(document).ready(function() { $('#calendar').fullCalendar({ header: { left: 'prev,next, today', center: 'title', right: 'month,agendaWeek,agendaDay' }, defaultDate: jQuery.now(), editable: false, eventLimit: true, // allow "more" link when too many events events: <?php echo json_encode($thejson); ?> }); }); </script> <div class="row"> <div class="col-md-12"> <div id="calendar"> </div> </div> </div> </section> </div> </div> 门票的数据库结构很简单:id、title、description、date_at、time_at、created_at、tecnico_id和status_id。 我想使用 if 脚本“着色”事件: 这是我的代码,但它不起作用。 <section class="content"> <?php $events = TicketData::getEvents(); // $status->status_id; foreach($events as $event){ $thejson[] = array("title"=>$event->title,"url"=>"./?view=editticket&id=".$event->id,"start"=>$event->date_at."T".$event->time_at,); $thejsonColor[] = array($event->status_id); } // print_r(json_encode($thejson)); ?> <script> $(document).ready(function() { $('#calendar').fullCalendar({ header: { left: 'prev,next, today', center: 'title', right: 'month,agendaWeek,agendaDay' }, defaultDate: jQuery.now(), editable: false, eventLimit: true, // allow "more" link when too many events events: <?php echo json_encode($thejson); ?>, if ($thejsonColor=1){ eventColor: 'fb8c00' }else if ($thejsonColor=2){ eventColor: 'ff0' } else if ($thejsonColor=3){ eventColor: '43a047' } else { eventColor: '00acc1' } }); }); </script> 我想让它们符合颜色标准,这样用户就可以知道哪些票是待处理的、不完整的、完整的和已取消的。 我是 javascript 的新手,我不知道如何做到这一点。你们能帮助我或指出我应该如何做吗? 您可以在迭代事件数组时设置颜色: <?php // helper function to pick the right color function getColor($id) { $eventColor = ''; if ($id == 1) { $eventColor = '#fb8c00'; } else if ($id == 2) { $eventColor = '#ff0'; } else if ($id == 3) { $eventColor = '#43a047'; } else { $eventColor = '#00acc1'; } return $eventColor; } $events = TicketData::getEvents(); //pulls the events from TicketData.php foreach($events as $event) { $thejson[] = array( "title" => $event->title, "url" => "./?view=editticket&id=".$event->id, "start" => $event->date_at."T".$event->time_at, "color" => getColor($event->status_id)); } ?> 然后就像你现在正在做的那样回显事件: <script> $(document).ready(function() { $('#calendar').fullCalendar({ header: { left: 'prev,next, today', center: 'title', right: 'month,agendaWeek,agendaDay' }, defaultDate: jQuery.now(), editable: false, eventLimit: true, // allow "more" link when too many events events: <?php echo json_encode($thejson); ?>, }); }); </script> 或者您可以通过从 php 中的表中选择来完成此操作,例如: $sql = "SELECT CASE WHEN tickets='Pending'" THEN '#C6E0B4' WHEN tickets='In progres' THEN '#FFFF99' END AS color" $schedules = $conn->query($sql); $sched_res = []; foreach($schedules->fetch_all(MYSQLI_ASSOC) as $row){ $sched_res[$row['id']] = $row; } 然后就像你现在正在做的那样回显事件: <script> $(document).ready(function() { $('#calendar').fullCalendar({ header: { left: 'prev,next, today', center: 'title', right: 'month,agendaWeek,agendaDay' }, defaultDate: jQuery.now(), editable: false, eventLimit: true, // allow "more" link when too many events events: <?php echo json_encode($thejson); ?>, }); }); </script>


仅返回与条件相关的最新记录

我有这样的关系: 公共函数latestEvent():HasOne { 返回 $this->hasOne(Event::class, 'client_id', 'id') ->whereIn('状态', ['已完成', '等待']) ...


具有 TimestampableEntity 特征的实体在 PUT 操作中失败

我正在全新安装 API Platform (v3.2.7),并且使用 Gedmo\Timestampable\Traits\TimestampableEntity 这是我的实体(问候语示例) 我正在全新安装 API Platform (v3.2.7),并且正在使用 Gedmo\Timestampable\Traits\TimestampableEntity 这是我的实体(问候语示例) <?php namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Gedmo\Timestampable\Traits\TimestampableEntity; #[ApiResource] #[ORM\Entity] class Greeting { use TimestampableEntity; #[ORM\Id] #[ORM\Column(type: "integer")] #[ORM\GeneratedValue] private ?int $id = null; #[ORM\Column] #[Assert\NotBlank] public string $name = ""; public function getId(): ?int { return $this->id; } } 和我的 config/services.yaml gedmo.listener.timestampable: class: Gedmo\Timestampable\TimestampableListener tags: - { name: doctrine.event_listener, event: 'prePersist' } - { name: doctrine.event_listener, event: 'onFlush' } - { name: doctrine.event_listener, event: 'loadClassMetadata' } 它在 POST 操作上工作正常,但在执行 PUT 时失败。我收到此错误 执行查询时发生异常:SQLSTATE[23000]: 完整性约束违规:1048 列“created_at”不能 空 我使用的版本是:symfony 6.4.1,doctrine 2.12,gedmo 3.14 我最终做的是使用 PATCH 而不是 PUT。所以我可以编辑部分实体,并且特征仍然更新 updated_at 字段


具有多个值的JS var

有件事我无法理解: 我有一个打开同一页面的功能,但具有不同的内容,具体取决于菜单中单击的按钮: 有件事我无法理解: 我有一个打开同一页面的功能<div id="page">但具有不同的内容,具体取决于菜单中单击的按钮: <nav> <button onclick="openPage(1)">PAGE 1</button> <button onclick="openPage(2)">PAGE 2</button> <button onclick="openPage(3)">PAGE 3</button> </nav> 然后是函数: function openPage(p){ var move=0; // define a var for USER action if(p==1){ document.getElementById('page').innerHTML = text_1; // content preloaded } else if(p==2){ document.getElementById('page').innerHTML = text_2; } else if(p==3){ document.getElementById('page').innerHTML = text_3; } // then on the top of the page (absolute + z-index) I add a HTML object: document.getElementById('page').innerHTML += '<aside id="pictures">content</aside>'; // what I'm now trying to do is to remove this object once USER move its mouse on it document.getElementById('pictures').addEventListener("mousemove",function(event) { setTimeout(function(){ move+=1; // increase the val each second },1e3) console.log('move'+p+' = '+move) // control value if(move>100){ document.getElementById('pictures').style.display = "none"; // OK, it works move=0; // reinit the var } }); } 现在惊喜: 第 1 页的控制台 move1 = 0 move1 = 1 ... move1 = 99 move1 = 100 // 'pictures' disappears 第 2 页的控制台 move1 = 41 move2 = 0 ... move1 = 58 move1 = 17 ... move1 = 100 // 'pictures' disappears move2 = 59 第 3 页的控制台 move1 = 15 move2 = 88 move3 = 0 ... move1 = 37 move2 = 100 // 'pictures' disappears move3 = 12 ... 我的 var 'move' 同时获得 3 个值...这怎么可能? 您的问题的原因是您每次调用 openPage 函数时都会添加一个事件侦听器。这意味着,如果您单击多个按钮,每个按钮都会有自己的事件侦听器附加到 #pictures 元素。现在,当触发 mousemove 事件时,所有这些侦听器将同时执行,导致 move 变量每秒递增多次。 解决此问题的方法是在添加新事件侦听器之前先删除现有的事件侦听器。 let handler; // to hold the event listener function const pictureEl = document.getElementById('pictures'); function openPage(p){ // Remove existing event listener if (handler) { // <-- Check here pictureEl.removeEventListener("mousemove", handler); } handler = function(event) { // ...Rest } }; // Add new event listener pictureEl.addEventListener("mousemove", handler); // ...rest 找到了另一种(最简单的?)方法: var move=0; // placed out of functions function openPage(p){ .... (same as previous) getElementById('pictures').addEventListener("mousemove",outPicts); // change } // put mousemove event in another function: function outPicts(p){ setTimeout(function(){ move+=1; },1e3) console.log('move = '+move) if(move>100){ document.getElementById('pictures').style.display = "none"; // then remove event getElementById('pictures').removeEventListener("mousemove",outPicts); move=0; // reinit the var } } 按预期工作


检测具有委托的元素内部的单击以及何时通过其类名称选择该元素

如何检测单击是否位于其侦听器被类选择的元素内部? 例如,我有一些类名为“my-class”的元素: 如何检测单击是否位于其侦听器被类选择的元素内部? 例如,我有一些类名为“my-class”的元素: <div class="my-class"> <button>Hello</button> <p>World</p> </div> <div class="my-class"> <a href="">Click</a> <a href="">Here</a> </div> 如果我只听课,点击内部元素是不行的: document.addEventListener("click", function(event) { if(event.target.classList.contains("my-class") { // } }); 我怎样才能检测到对其中任何元素的点击? 我发现了以下问题,但它仅适用于由 id 选择且没有委托的单个元素: Detect click inside/outside of element with single event handler 使用Element::closest()检查被点击的元素是在my-class内部还是my-class本身: https://developer.mozilla.org/en-US/docs/Web/API/Element/closest document.addEventListener("click", function(event) { if(event.target.closest(".my-class")) { console.log('my-class clicked!'); } event.preventDefault(); }); <div class="my-class"> <button>Hello</button> <p>World</p> </div> <div class="my-class"> <a href="">Click</a> <a href="">Here</a> </div>


如何使用 Javascript 单击按钮来获取按钮内的文本?

我需要 html 段落中的结果 这里是按钮文本 这是Html部分 我需要这个文本... 我需要 html 段落中的结果 <p id="result">Here the Button Text</p> 这是Html部分 <button type="button" id="vteam">i need this text</button> 这是JS部分 $(document).on('click', '.vteam', function(event) {} event.target指的是单击的元素,因此您可以像这样获取其中的文本:event.target.innerText。 我认为你可以使用以下内容: function changeText() { document.getElementById("vteam").innerHTML = "Hello"; } 和 <p id="vteam" onclick="changeText()">I need this text to change</p> 嘿我最近找到了解决这个问题的简单方法: 您可以将内部文本作为元素的 id 提供。在事件处理程序中,您可以通过以下方式访问内部文本: e.目标.id 希望这个解决方案可以帮助您:)


参数'event'和'event'类型不兼容

我有一个项目,是一个员工监控项目,它有几个组件,这些组件中有一组按钮在一起。 我有一组按钮,我称之为


MySQL 事件——执行需要 EVENT 权限吗?

MySQL 5.7 (Win) 和 MariaDB 10.1 (Linux),事件计划程序设置为 ON,我以 root 身份连接。 创建数据库“事件测试”; 创建用户“event-test”@“localhost”,由“password-is-here”标识; 格...


Javascript:如何获取单击按钮的innerHTML

构建了一个小费计算器,但希望通过获取正在单击的按钮的innerHTML来缩短代码。 账单总额: 构建了一个小费计算器,但想通过获取正在单击的按钮的innerHTML来缩短代码。 Total Bill: <input id="bill" type="text"> <button type="button" onclick="tip15()">15</button> <button type="button" onclick="tip18()">18</button> <button type="button" onclick="tip20()">20</button> <div id="tip">You owe...</div> function tip15(){ var totalBill = document.getElementById("bill").value; var totalTip = document.onclick.innerHTML var tip = totalBill * 0.15; document.getElementById("tip").innerHTML = "&#36;" +tip } 这种方法的问题是我必须写出三个版本的函数来与小费金额相对应。我想创建一个函数来获取被单击按钮的innerHTML 并在函数中使用该值。我希望它看起来像这样 function tip(){ var totalBill = document.getElementById("bill").value; **var totalTip = GET INNERHTML OF CLICKED BUTTON** var tip = totalBill * ("." + totalTip); document.getElementById("tip").innerHTML = "&#36;" +tip } 这样我就可以在不同的按钮上运行相同的功能。 使用 HTML5 数据属性。 <button type="button" data-tip="15" onclick="getTip(this)">15</button> 您传递给函数的参数this指的是正在单击的按钮。然后你就可以得到这样的属性值: function tip(button){ var tip= button.getAttribute("data-tip"); ... } 剩下的留给你了。 像这样改变:将值传递给tip函数。 <button id="15" type="button" onclick="tip(15)">15</button> <button id="18" type="button" onclick="tip(18)">18</button> <button id="20" type="button" onclick="tip(20)">20</button> function tip(tip_value) { /*use here tip_value as you wish you can use if condition to check the value here*/ var totalBill = document.getElementById("bill").value; var totalTip = tip_value; var tip = totalBill * ("." + totalTip); document.getElementById("tip").innerHTML = "&#36;" +tip; } 将 this.innerHTML 作为参数传递给您的小费函数。 所以你的小费函数应该是这样的: function tip(totalTip) { var totalBill = document.getElementById("bill").value; var tip = totalBill * ("." + totalTip); document.getElementById("tip").innerHTML = "&#36;" +tip } 因此,如果您有一个如下所示的按钮元素: <button type="button" onclick="tip(this.innerHTML)">15</button> 提示函数将被称为 tip(15)。 我会写一个快速解决方案,然后解释为什么我这样做。 建议的解决方案 第 1 部分,HTML <div id="tip-wrapper"> <label for="bill">Total bill:</label> <input name="bill" id="bill" type="text"> <br/> <label for="tipratio">Tip ratio:</label> <button name="tipratio" value="15" type="button">15%</button> <button name="tipratio" value="18" type="button">18%</button> <button name="tipratio" value="20" type="button">20%</button> <div id="final-value">You owe...</div> </div> 第 2 部分,JavaScript var parent = document.getElementById('tip-wrapper'), buttons = parent.getElementsByTagName('button'), max = buttons.length, i; // function that handles stuff function calculate (e) { var bill = document.getElementById('bill'), tipRatio = e.target.value; document.getElementById('final-value').textContent = bill.value * (1+tipRatio/100); } // append event listeners to each button for(i = 0; i < max; i++) { buttons[i].addEventListener('click', calculate, true); } 说明 关于 HTML,并没有“太多”改变。唯一的事情是我使用的东西更符合标准。 我添加了一个 wrapper 元素,这只是为了隔离一些 DOM 遍历,而不是遍历整个文档对象来进行查找(这将加快您的脚本速度)。 您的按钮使用“值”属性,这是最好的。因为您可以以一种方式显示按钮文本,但使用正确的值(请参阅我添加了 % 字符)。 除此之外,我主要添加了适当的标识符和标签。 JavaScript,这是我将更详细地介绍的地方,我将逐步介绍: 您在脚本中要做的第一件事是设置您需要的变量(并获取您将使用的 DOM 元素。这就是我在前 4 行代码中所做的事情。 创建一个通用函数来处理您的计算并更新您的元素,无论其数值如何。我在这里使用的功能是向您的函数添加一个参数 (e),因为 javascript 中的 EVENTS 将 EVENT OBJECT 附加到您的回调函数(在本例中为 calculate();)。 EVENT OBJECT 实际上有很多有用的属性,我使用其中的: target:这是触发事件的元素(即您的按钮之一) 我们所要做的就是获取目标值 (e.target.value) 并将其用于返回最终账单的数学中。 使用addEventListener。人们普遍认为应该将 JavaScript 保留在 HTML 之外,因此不鼓励使用旧的事件方法 (onclick="")。 addEventListener()方法并不太复杂,不做详细介绍,其工作原理如下: htmlObject.addEventListener('事件类型', '回调函数', '冒泡true/false'); 我所做的只是循环遍历所有按钮并附加事件 lsitener。 结束语 使用此脚本,您现在可以添加任何您想要的“按钮”,脚本会将它们全部考虑在内并进行相应调整。只要确保设置它们的“值”即可。 当我写这篇文章时,一些人给出了一些快速的答案。我还不能发表评论(声誉低),所以我会在这里留下我的评论。 一些建议的答案告诉您使用innerHTML来获取小费值。这是错误的,您正在使用表单字段,应该使用 element.value,这就是它的用途。 有些人甚至敢说使用 HTML5 data-* 属性。当然,你可以。但你为什么要这么做呢? HTML 和 DOM 已经提供了完成任务所需的所有工具,而无需使用不必要的属性来污染 HTML。 value="" 属性旨在在表单中使用,它应该在字段值的 data-* 属性上使用。 一般来说,innerHTML旨在获取 HTML,而不一定是文本或值。还有其他方法可以获取您正在寻找的值。对于表单元素,它是 element.value,对于大多数其他 HTML 元素,它是 element.textContent。 希望这些解释有帮助 function tip(o) { var input = document.querySelector("input[id='bill']"); var total = input.value * o.innerHTML; document.querySelector("#tip").innerHTML = "&#36;" + total; } Total Bill: <input id="bill" type="text"> <button type="button" onclick="tip(this)">15</button> <button type="button" onclick="tip(this)">18</button> <button type="button" onclick="tip(this)">20</button> <div id="tip">You owe...</div> 嘿我最近找到了解决这个问题的简单方法: 您可以将内部文本作为元素的 id 提供。在事件处理程序中,您可以通过以下方式访问内部文本: e.目标.id 希望这个解决方案可以帮助您:)


如何从字典列表中删除重复值[重复]

这是我的清单: my_list = [{'id': '5927'}, {'id': '5931'}, {'id': '5929'}, {'id': '5930'}, {'id': '5928 '}, {'id': '5929'}, {'id': '5930'}] 如果 id 的值重复,我将删除它。 我...


使用discord.js在频道中发送欢迎消息

我开始使用discord.js 编写一个discord 机器人。我还遵循他们提供的指南,直到完成“事件处理”:https://discordjs.guide/creating-your-bot/event-handl...


Flatpickr AlpineJS 在危险范围选择上坚持插件

我有一个工作完美的 Flatpickr 日期范围日历,它将日期存储在会话存储中。这是我的代码: 我有一个工作完美的 Flatpickr 日期范围日历,它将日期存储在会话存储中。这是我的代码: <div x-data="{ chosenDates: sessionStorage.getItem('_x_range'), value: [], init() { let picker = flatpickr(this.$refs.picker, { mode: 'range', inline: false, dateFormat: 'm/d/Y', showMonths: 2, }) this.$watch('value', () => picker.setDate(this.value)) }, }" > <div class="flex items-center flex-1 gap-2 overflow-hidden border border-gray-500 rounded-lg"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="ml-4 bi bi-calendar-event-fill" viewBox="0 0 16 16"> <path d="M4 .5a.5.5 0 0 0-1 0V1H2a2 2 0 0 0-2 2v1h16V3a2 2 0 0 0-2-2h-1V.5a.5.5 0 0 0-1 0V1H4zM16 14V5H0v9a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2m-3.5-7h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5"/> </svg> <input id="rangeValue" :value="chosenDates" placeholder="Add dates" x-ref="picker" type="text" class="p-0 py-4 placeholder-gray-600 border-0 bg-none focus:ring-0 " data-input> </div> </div> 设置项目: function dateRange() { var date = document.getElementById("rangeValue").value; sessionStorage.setItem("_x_range", date); sessionStorage.setItem("start", start); sessionStorage.setItem("end", end); const start = sessionStorage.getItem("start"); } $('#rangeValue').on('focus', ({ currentTarget }) => $(currentTarget).blur()) $("#rangeValue").prop('readonly', false) ``` Receive item: if (sessionStorage.getItem("_x_range") != null) { document.getElementById("chosenRange").innerHTML = sessionStorage.getItem("_x_range"); document.getElementById("rangeValue").value = sessionStorage.getItem("_x_range"); } ``` 如果可能的话,我想学习如何使用 AplineJS 和 Persist 来设置它,以免代码过多而过期。 这可能吗? 这是一个可能的解决方案: <div x-data="{ thePicker: null, chosenDates: $persist([]).using(sessionStorage).as('_x_range'), init() { this.thePicker = flatpickr(this.$refs.picker, { mode: 'range', inline: false, dateFormat: 'm/d/Y', showMonths: 2, defaultDate: this.chosenDates, onChange: (selectedDates) => {this.chosenDates = [...selectedDates];} }); }, }" > <div class="flex items-center flex-1 gap-2 overflow-hidden border border-gray-500 rounded-lg"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="ml-4 bi bi-calendar-event-fill" viewBox="0 0 16 16"> <path d="M4 .5a.5.5 0 0 0-1 0V1H2a2 2 0 0 0-2 2v1h16V3a2 2 0 0 0-2-2h-1V.5a.5.5 0 0 0-1 0V1H4zM16 14V5H0v9a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2m-3.5-7h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5"/> </svg> <input type="text" x-ref="picker" placeholder="Add dates" class="p-0 py-4 placeholder-gray-600 border-0 bg-none focus:ring-0" > <span title="Clear" class="text-blue-600 cursor-pointer" @click="thePicker.clear()" > X </span> </div> <div x-text="chosenDates"> </div> </div> 日期范围存储在 Alpine chosenDates 变量中,该变量通过 Persist 进行持久化并初始化为空数组。 当日期选择器初始化时,chosenDates变量用于填充defaultDate参数。 选择日期范围后,flatpicker 会触发 onChage 事件,因此我使用它将新范围复制到 chosenDates 变量中。 我添加了一个 “clear” 按钮以 flatpicker 方式重置输入字段,调用 clear() 方法(这是一个简单的示例),然后我必须将 flatpicker 引用存储在 thePicker 中变量. 我还添加了一个 通过 x-text 显示 choosenDates 的内容


Flutter 中的状态错误

如何修复此错误:StateError(错误状态:在没有注册事件处理程序的情况下调用 add(SignUp Button Pressed)。请确保通过 on((event, eager) {...}) 注册处理程序) 注册区: 重要...


单击 p 标签旁边的按钮时获取 p 标签的内部文本(无 Jquery)

我有几个盒子,每个盒子都包含按钮和一个 元素,其内部文本是由 API 中的数据创建的。我在每个框上放置了一个 onclick(包裹 的 ) 我有几个盒子,每个盒子都包含按钮和一个 <p> 元素,其内部文本是由 API 中的数据创建的。我在每个框上放置了一个 onclick(包裹 <div> 元素和按钮的 <p>)。我希望每次单击该按钮时,位于该按钮旁边(位于同一 div 中)的 innerText 标签的 <p> 都会控制台日志。目前无法弄清楚,这就是我到目前为止所得到的: const containerShapes = document.getElementById("container-pock-shape") fetch("https://pokeapi.co/api/v2/pokemon-shape") .then(res => res.json()) .then(data => data.results.map(item => { return containerShapes.innerHTML += `<div class="shape-box" onclick="showName(event)"> <p>${item.name}</p> <button>Select</button> </div>` })) function showName(e) { console.log() } #container-pock-shape { display: flex; flex-wrap: wrap; } .shape-box { border: 2px solid red; display: flex; flex-direction: column; align-items: center; padding: 10px; width: 200px; } .shape-box p { background-color: grey; width: 100px; text-align: center; font-weight: 900; } <body> <div id="container-pock-shape"> </div> </body> 您可以使用最近的。当您需要 forEach 或正确使用地图时也不要使用地图 我还强烈建议授权(点击 div) const containerShapes = document.getElementById("container-pock-shape") fetch("https://pokeapi.co/api/v2/pokemon-shape") .then(res => res.json()) .then(data => containerShapes.innerHTML = data.results .map(({name}) => `<div class="shape-box"> <p>${name}</p> <button>Select</button> </div>`)); containerShapes.addEventListener("click", e => { const tgt = e.target.closest("button") if (tgt) console.log(tgt.closest("div.shape-box").querySelector("p").innerText) }) #container-pock-shape { display: flex; flex-wrap: wrap; } .shape-box { border: 2px solid red; display: flex; flex-direction: column; align-items: center; padding: 10px; width: 200px; } .shape-box p { background-color: grey; width: 100px; text-align: center; font-weight: 900; } <body> <div id="container-pock-shape"></div> </body> 要获取名称,由于事件位于整个 div 上,因此您需要使用 querySelector 并找到内部 <p> 元素并获取其文本。 const containerShapes = document.getElementById("container-pock-shape") fetch("https://pokeapi.co/api/v2/pokemon-shape") .then(res => res.json()) .then(data => data.results.map(item => containerShapes.innerHTML += `<div class="shape-box" onclick="showName(this)"> <p>${item.name}</p> <button>Select</button> </div>` )) function showName(box) { const name = box.querySelector('p').textContent; console.log(name); } #container-pock-shape { display: flex; flex-wrap: wrap; } .shape-box { border: 2px solid red; display: flex; flex-direction: column; align-items: center; padding: 10px; width: 200px; } .shape-box p { background-color: grey; width: 100px; text-align: center; font-weight: 900; } <body> <div id="container-pock-shape"></div> </body> 执行此操作的另一种方法是将单击事件仅添加到按钮,然后查找 closest 形状框,然后找到 <p>。 const containerShapes = document.getElementById("container-pock-shape") fetch("https://pokeapi.co/api/v2/pokemon-shape") .then(res => res.json()) .then(data => data.results.map(item => containerShapes.innerHTML += `<div class="shape-box"> <p>${item.name}</p> <button onclick="showName(this)">Select</button> </div>` )) function showName(button) { const name = button.closest('.shape-box').querySelector('p').textContent; console.log(name); } #container-pock-shape { display: flex; flex-wrap: wrap; } .shape-box { border: 2px solid red; display: flex; flex-direction: column; align-items: center; padding: 10px; width: 200px; } .shape-box p { background-color: grey; width: 100px; text-align: center; font-weight: 900; } <body> <div id="container-pock-shape"></div> </body> 嘿,我最近找到了解决此问题的简单方法(当然,如果您的文本不像按钮文本那样太长):您可以将内部文本作为元素的 id 提供。并且在事件处理程序中,您可以通过以下方式访问内部文本:这样:e.target.id希望这个解决方案可以帮助你:)


无法在 /api/something/server.js 中使用 setHeaders 设置标头

有人能解释一下如何在 sveltekit 中的 api/something/+server.js 中设置标头吗? 我在这里阅读了文档 都是关于 +page.server.js 但不是 api/folder/+server.js 导出异步函数 POST(event)...


错误:在此 BlocBuilder<InternetBloc> Widget<InternetBloc, InternetState> 上方找不到正确的提供程序

我在尝试将 flutter_bloc 集成到 flutter 项目中时遇到错误。 错误:在此 BlocBuilder 上方找不到正确的 Provider 我在尝试将 flutter_bloc 集成到 flutter 项目中时遇到错误。 错误:在此 BlocBuilder Widget 上方找不到正确的提供者 这是我正在使用的代码示例。 internet_state.dart abstract class InternetState{} class InitialInternetState extends InternetState{} class LostConnectionInternetState extends InternetState{} class GainConnectionInternetState extends InternetState{} internet_event.dart abstract class InternetEvent{} class LostConnectionEvent extends InternetEvent{} class GainConnectionEvent extends InternetEvent{} internet_bloc.dart class InternetBloc extends Bloc<InternetEvent, InternetState>{ final Connectivity _connectivity = Connectivity(); StreamSubscription? streamSubscription; InternetBloc() : super(InitialInternetState()){ on<GainConnectionEvent>((event, emit) => emit(GainConnectionInternetState())); on<LostConnectionEvent>((event, emit) => emit(LostConnectionInternetState())); _connectivity.onConnectivityChanged.listen((event) { if(event == ConnectivityResult.mobile || event == ConnectivityResult.wifi){ add(GainConnectionEvent()); } else { add(LostConnectionEvent()); } }); } @override Future<void> close() { streamSubscription?.cancel(); return super.close(); } } main.dart class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatelessWidget { const MyHomePage({super.key, required this.title}); final String title; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(title),), body: SafeArea( child: Center(child: BlocBuilder<InternetBloc, InternetState>( builder: (context, state) { return const Text("hello"); }, )), ),); } } 我明白了。 ======== 小部件库捕获异常====================================== =================== 构建 MediaQuery(MediaQueryData(size: Size(392.7, 783.3), devicePixelRatio: 2.8, textScaler: noscaling, platformBrightness: Brightness.light, padding: EdgeInsets.zero, viewPadding: EdgeInsets.zero, viewInsets: EdgeInsets 时抛出以下 ProviderNotFoundException。零,systemGestureInsets:EdgeInsets(29.8,24.0,29.8,8.0),alwaysUse24HourFormat:假,accessibleNavigation:假,highContrast:假,onOffSwitchLabels:假,disableAnimations:假,invertColors:假,boldText:假,navigationMode:传统,gestureSettings:DeviceGestureSettings (touchSlop:8.0),显示功能:[])): 错误:无法在此 BlocBuilder Widget 之上找到正确的提供程序 发生这种情况是因为您使用了不包含提供程序的 BuildContext 你的选择。有以下几种常见场景: 您在main.dart中添加了一个新的提供程序并执行了热重载。 要修复此问题,请执行热重启。 您尝试阅读的提供商处于不同的路线。 提供商具有“范围”。因此,如果您在路线中插入提供者,那么 其他路线将无法访问该提供商。 您使用了 BuildContext,它是您尝试读取的提供程序的祖先。 确保 BlocBuilder 位于您的 MultiProvider/Provider 下。 当您创建提供程序并尝试立即读取它时,通常会发生这种情况。 例如,代替: Widget build(BuildContext context) { return Provider<Example>( create: (_) => Example(), // Will throw a ProviderNotFoundError, because `context` is associated // to the widget that is the parent of `Provider<Example>` child: Text(context.watch<Example>().toString()), ); } 考虑使用builder,如下所示: Widget build(BuildContext context) { return Provider<Example>( create: (_) => Example(), // we use `builder` to obtain a new `BuildContext` that has access to the provider builder: (context, child) { // No longer throws return Text(context.watch<Example>().toString()); } ); } 如果这些解决方案都不起作用,请考虑在 StackOverflow 上寻求帮助: https://stackoverflow.com/questions/tagged/flutter The relevant error-causing widget was: SafeArea SafeArea:file:///Users/../Projects/flutterTest/bloc_test/lib/main.dart:37:13 When the exception was thrown, this was the stack: #0 Provider._inheritedElementOf (package:provider/src/provider.dart:343:7) #1 Provider.of (package:provider/src/provider.dart:293:30) #2 ReadContext.read (package:provider/src/provider.dart:649:21) #3 _BlocBuilderBaseState.initState (package:flutter_bloc/src/bloc_builder.dart:130:36) #4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5602:55) #5 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5) ... Normal element mounting (4 frames) #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16) #10 Element.updateChild (package:flutter/src/widgets/framework.dart:3831:20) #11 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #12 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #13 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #14 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #15 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6743:14) #16 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #17 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #18 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #19 StatelessElement.update (package:flutter/src/widgets/framework.dart:5547:5) #20 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #21 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #22 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #23 StatelessElement.update (package:flutter/src/widgets/framework.dart:5547:5) #24 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #25 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #26 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #27 StatelessElement.update (package:flutter/src/widgets/framework.dart:5547:5) #28 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #29 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #30 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #31 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #32 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #33 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #34 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #35 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #36 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #37 Element.updateChildren (package:flutter/src/widgets/framework.dart:3964:32) #38 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6896:17) #39 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #40 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #41 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #42 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #43 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #44 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #45 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #46 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #47 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #48 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #49 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #50 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #51 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #52 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #53 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #54 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #55 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #56 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #57 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #58 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #59 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #60 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #61 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #62 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #63 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6743:14) #64 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #65 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #66 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #67 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #68 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #69 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6743:14) #70 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #71 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #72 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #73 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #74 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #75 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #76 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #77 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #78 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #79 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #80 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #81 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #82 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #83 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #84 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #85 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #86 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #87 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #88 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #89 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #90 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #91 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #92 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #93 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #94 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #95 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #96 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #97 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #98 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #99 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #100 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #101 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #102 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #103 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #104 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #105 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #106 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #107 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #108 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #109 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2895:19) #110 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:984:21) #111 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:457:5) #112 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1325:15) #113 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1255:9) #114 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:978:7) #118 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12) (elided 3 frames from class _Timer and dart:async-patch) ==================================================================================================== 我不想使用像 MultiProvider 这样的全局提供程序。 您应该在某处创建 InternetBloc 并提供它。 MultiProvider 本身并不是全局的,它只是多个。 更多信息在这里:https://bloclibrary.dev/#/flutterbloccoreconcepts?id=blocprovider 所以,如果您不想使用全局提供程序,它将看起来像这样: class MyHomePage extends StatelessWidget { const MyHomePage({super.key, required this.title}); final String title; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(title), ), body: SafeArea( child: Center( child: BlocProvider<InternetBloc>( create: ( context) => InternetBloc(), child: BlocBuilder<InternetBloc, InternetState>( builder: (context, state) { return const Text("hello"); }, ), ), ), ), ); } } 要使用 BlocBuilder,您需要在 Widget 树中放置一个 BlocProvider。最佳实践是将其放置得尽可能深。在您的情况下,只需将 BlocProvider 放在 BlocBuilder 之上。 此外 MultiProvider / MultiBlocProvider 不是全局 Provider。它只是一个提供多个 Provider/BlocProvider 的便捷小部件。 class MyHomePage extends StatelessWidget { const MyHomePage({super.key, required this.title}); final String title; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(title), ), body: SafeArea( child: Center( // Now everything below that can access the InternetBloc child: BlocProvider<InternetBloc>( create: (_) => InternetBloc(), child: BlocBuilder<InternetBloc, InternetState>( builder: (context, state) { return const Text("hello"); }, ), ), ), ), ); } }


显示输入类型日期的占位符文本

占位符不适用于直接输入类型日期和日期时间本地。 占位符不适用于直接输入类型 date 和 datetime-local。 <input type="date" placeholder="Date" /> <input type="datetime-local" placeholder="Date" /> 该字段在桌面上显示 mm/dd/yyy,而在移动设备上则不显示任何内容。 如何显示 Date 占位符文本? 使用onfocus="(this.type='date')",例如: <input required="" type="text" class="form-control" placeholder="Date" onfocus="(this.type='date')"/> 使用onfocus和onblur...这是一个例子: <input type="text" placeholder="Birth Date" onfocus="(this.type='date')" onblur="if(this.value==''){this.type='text'}"> 在这里,我尝试了 data 元素中的 input 属性。并使用 CSS 应用所需的占位符 <input type="date" name="dob" data-placeholder="Date of birth" required aria-required="true" /> input[type="date"]::before { content: attr(data-placeholder); width: 100%; } /* hide our custom/fake placeholder text when in focus to show the default * 'mm/dd/yyyy' value and when valid to show the users' date of birth value. */ input[type="date"]:focus::before, input[type="date"]:valid::before { display: none } <input type="date" name="dob" data-placeholder="Date of birth" required aria-required="true" /> 希望这有帮助 <input type="text" placeholder="*To Date" onfocus="(this.type='date')" onblur="(this.type='text')" > 这段代码对我有用。只需使用这个即可 对于 Angular 2,你可以使用这个指令 import {Directive, ElementRef, HostListener} from '@angular/core'; @Directive({ selector: '[appDateClick]' }) export class DateClickDirective { @HostListener('focus') onMouseFocus() { this.el.nativeElement.type = 'date'; setTimeout(()=>{this.el.nativeElement.click()},2); } @HostListener('blur') onMouseBlur() { if(this.el.nativeElement.value == ""){ this.el.nativeElement.type = 'text'; } } constructor(private el:ElementRef) { } } 并像下面一样使用它。 <input appDateClick name="targetDate" placeholder="buton name" type="text"> 对于 React,你可以这样做。 const onDateFocus = (e) => (e.target.type = "datetime-local"); const onDateBlur = (e) => (e.target.type = "text"); . . . <input onFocus={onDateFocus} onBlur={onDateBlur} type="text" placeholder="Event Date" /> 我是这样做的: var dateInputs = document.querySelectorAll('input[type="date"]'); dateInputs.forEach(function(input) { input.addEventListener('change', function() { input.classList.add('no-placeholder') }); }); input[type="date"] { position: relative; } input[type="date"]:not(.has-value):before { position: absolute; left: 10px; top: 30%; color: gray; background: var(--primary-light); content: attr(placeholder); } .no-placeholder:before{ content:''!important; } <input type="date" name="my-date" id="my-date" placeholder="My Date"> 现代浏览器使用 Shadow DOM 来方便输入日期和日期时间。因此,除非浏览器出于某种原因选择回退到 text 输入,否则不会显示占位符文本。您可以使用以下逻辑来适应这两种情况: ::-webkit-calendar-picker-indicator { @apply hidden; /* hide native picker icon */ } input[type^='date']:not(:placeholder-shown) { @apply before:content-[attr(placeholder)]; @apply sm:after:content-[attr(placeholder)] sm:before:hidden; } input[type^='date']::after, input[type^='date']::before { @apply text-gray-500; } 我使用了 Tailwind CSS 语法,因为它很容易理解。让我们一点一点地分解它: ::-webkit-calendar-picker-indicator { @apply hidden; /* hide native picker icon */ } 使用其 Shadow DOM 伪元素选择器隐藏本机选择器图标(通常是日历)。 input[type^='date']:not(:placeholder-shown) { @apply before:content-[attr(placeholder)]; @apply sm:after:content-[attr(placeholder)] sm:before:hidden; } 选择所有未显示占位符的 date 和 datetime-local 输入,并且: 默认使用 placeholder 伪元素显示输入 ::before 文本 在小屏幕及以上屏幕上切换为使用 ::after 伪元素 input[type^='date']::after, input[type^='date']::before { @apply text-gray-500; } 设置 ::before 和 ::after 伪元素的样式。


Vue js & laravel 后端编辑发票

编辑: 我正在从发票项目中获取这些数组,其中产品与发票 ID 相匹配 [ { “ID”:27, “发票 ID”:14, “产品id”:1, ...


QtQuick - “父项”是什么意思?

以下QML代码: 窗户 { id: 窗口 宽度:450 高度:700 可见:真实 堆栈视图{ id: 主栈 属性项目 itemTest: 项目 { id:项目...


为什么 Mongodb 不会自动创建“id”,以及如何禁用它

{ “_ID”: { “$oid”:“65ea05dbaa907e05219c0934” }, “id”:6, “标题”:“asd”, “内容”:“asd”, “自动...


使用 JSON_VALUE 访问 JSON 数组

我在 SQL Server 数据库中有一个包含两列(Id+结果)的表(Deltails), 其中 Id 是主键,Result 包含 JSON 对象。 此结果栏 [{"ID":"2023","


使用javascript过滤数组中所有最接近值的项目

我有一个排序数组是 数组 = [ { id: 1, 订单总数: 50000 }, { id: 3, 订单总数: 50000 }, { id: 2, 订单总数: 100000 }, { id: 4, 订单总数: 200000 }, ] 我想找到所有订单


Angular DI useFactory 将参数传递给工厂函数

如何将参数(数字)传递给工厂函数: 常量 ID = 1; { 提供:MyClass,useFactory:myFactory,deps:[ActivatedRoute] } //这里如何传递id? 函数 myFactory(id,


JavaScript 对象删除 人物

我正在从 API 接收一些数据 { “id”:1, “名称”:“梅尔克”, “内容”: ”{ \“1\”:{ \"主题ID\": 1, \&...


带有对象 ID 的特殊 Python 字典

我想创建一个特殊的字典,使用对象 ID 作为键,如下所示: 类 ObjectIdDict(dict): def __setitem__(自身,键,值): super(ObjectIdDict, self).__setitem__(id(k...


产品 ID 未定义

我正在尝试获取产品,它来自后端,但有时会显示产品 ID 未定义?不知道拿到产品和ID后显示如何。 导入 { 布局 } ...


检查 JavaScript 或 Angular 中的数组对象中是否存在值

我想检查数组对象中是否存在某个值。例子: 我有这个数组: [ {id: 1, 名称: 'foo'}, {id: 2, name: '酒吧'}, {id:3,名称:'测试'} ] 我想检查 id = 2 是否存在...


使用javascript过滤数组中具有最低最近值的所有项目

我有一个排序数组是 数组 = [ { id: 1, 订单总数: 50000 }, { id: 3, 订单总数: 50000 }, { id: 2, 订单总数: 100000 }, { id: 4, 订单总数: 200000 }, ] 我想找到所有订单


如何使用正则表达式验证十进制数

我有以下json: [ { “id”:1, “姓名”:“杰克”, “工资”:23.03 }, { “id”:2, “name”:“卢克&...


外连接data.tables,避免重复列

我有两个这样的表,其中大多数 id 是共享的,但都包含另一个表中不存在的 id。年份(列)也重叠但有差异: 表 1 <- data.table(id=c(&quo...


Redis:我们可以使用相对于当前时间的过去时间戳中的 ID 进行 XADD

我想保存相对于当前时间的过去时间的带有ID的数据。 例子: 最后 ID:(无) 当前时间:1904878793327 跑步: xadd测试1804878793327-1测试123 会抛出错误,ERR ID


SQL:连接具有相同 ID 的多行

我想加入 2 张桌子。两者具有相同的 ID 字段。然而,在一张表中可以存在具有相同 ID 的多行的功能。该表中有一个字段...


setState 不是一个函数 - 尝试使用按钮 id setState 以在 useParams 中用于页面导航

我正在尝试在单击 id 后更新按钮的状态。然后,这个 id 被存储在状态中,以便它可以作为参数传递,以导航到与 bu 具有相同 id 的页面...


如何控制列表元素抛出键盘事件

https://stackblitz.com/edit/react-o1ra7c 用户搜索结果后,用户尝试使用键盘事件箭头需要向下移动。 https://stackblitz.com/edit/react-o1ra7c 用户搜索结果后,用户尝试使用键盘事件箭头需要向下移动。 <div> <input onChange={handleSearchChange}/> <div css={countryDataCss}> {countryList?.map((country) => ( <div key={country.countryCode}> <span css={countryCss}>{country.countryName}</span> <span css={countryDialCodeCss}> {country.countryDialNo} </span> </div> ))} </div> </div> 您可以使用 javascirpt 事件 onkeydown,对于 React 来说是 onKeyDown,它提供了所需的行为,请检查下面的 stackblitz! import React from 'react'; import './style.css'; import { useState } from 'react'; export default function App() { const [searchText, setSearchText] = useState(''); const [selectedCountry, setSelectedCountry] = useState('SG'); const [activeIndex, setActiveIndex] = useState(0); const [selectedDialCode, setSelectedDialCode] = useState('+65'); const countryCodeListResponse = [ { countryCode: 'IND', countryDialNo: '+91', countryName: 'India' }, { countryCode: 'SG', countryDialNo: '+65', countryName: 'Singpare' }, ]; const [countryList, setCountryList] = useState(countryCodeListResponse); function handleSearchChange(e) { const searchText = e.target.value.toLowerCase(); if (countryCodeListResponse) { const updatedList = countryCodeListResponse .filter((el) => el.countryName.toLowerCase().includes(searchText)) .sort( (a, b) => a.countryName.toLowerCase().indexOf(searchText) - b.countryName.toLowerCase().indexOf(searchText) ); setSearchText(searchText); setCountryList(updatedList); } } const onSelectCountry = (code, dialCode) => { setSelectedCountry(code); setSelectedDialCode(dialCode); setSearchText(''); setCountryList(countryCodeListResponse); }; const onKeyDown = (event) => { console.log(event); switch (event.keyCode) { case 38: // arrow up if (activeIndex > 0 && activeIndex <= countryList.length - 1) { setActiveIndex((prev) => prev - 1); } break; case 40: // arrow down if (activeIndex >= 0 && activeIndex < countryList.length - 1) { setActiveIndex((prev) => prev + 1); } break; case 13: const country = countryList[activeIndex]; onSelectCountry(country.countryCode, country.countryDialNo); break; default: break; } }; return ( <div class="dropdown"> <div class="search"> <div> <span>{selectedCountry}</span> <span>{selectedDialCode}</span> </div> <input class="search-input" onKeyDown={(e) => onKeyDown(e)} placeholder="Search" value={searchText} onChange={handleSearchChange} /> </div> <div class="list"> {countryList?.map((country, index) => ( <div onKeyDown={(e) => onKeyDown(e)} className={index === activeIndex ? 'active' : ''} tabIndex="0" key={country.countryCode} onClick={() => onSelectCountry(country.countryCode, country.countryDialNo) } > <span>{country.countryName}</span> <span>{country.countryDialNo}</span> </div> ))} </div> </div> ); } 堆栈闪电战


Laravel Cashier Stripe 错误default_ payment_method

我需要进行用户订阅Stripe。我使用支付页面: 公共函数 paymentForm() { $id = equest()->get('id'); $plan = Plan::find(1); $intent = auth()->user()->


跨3列递归查询(OrderID、OriginalOrderID、GroupOrderID)

我有一个 SQL 表,其中特别包含 3 个感兴趣的列: 订单ID、原始订单ID、父订单ID 列的使用对于这个问题并不重要。尽管如此,OrderID 是...


如何从用户 ID 中检索 Instagram 用户名?

如何使用 Instagram 的 API 或网站从其 ID 检索 Instagram 用户名?我已经获得了一个包含 Instagram 用户 ID 的数据库表,我需要知道他们的用户名。


MS SQL 跨 3 列递归查询(OrderID、OriginalOrderID、GroupOrderID)

我有一个 SQL 表,其中特别包含 3 个感兴趣的列: 订单ID、原始订单ID、父订单ID 列的使用对于这个问题并不重要。尽管如此,OrderID 是...


每个产品的sql id计数

我有这个表格,我想在其中计算每个客户 ID 的产品数量。 我有 3 个不同的product_id 我当前的表格如下所示: 客户ID 产品编号 1 1001 1 1002 1 1003 2...


如何在 Java Selenium 中创建包含多个连接定位器的工厂元素定位器

例如,页面有一个定位器 id =“test1”的容器字段和另一个定位器 id =“field1”的字段 加入的定位器应在定位器 id = "...


使用mongo仓库时参数没有名称错误

我有下一个存储库: 接口 UserRepository 扩展 MongoRepository { 可选 findById(@Param("id") String id); } 当我尝试使用方法 fin 时...


如何从进程id获取主窗口句柄?

如何从进程ID获取主窗口句柄? 我想把这个窗口放在前面。 它在“Process Explorer”中运行良好。


如何使用 Azure 数据工厂将 SQL 表行转换为 CosmosDB NoSQL 中对象数组的第一个元素

我有一个包含3列的表:ID、A和B,我需要将数据转换为具有特定结构的CosmosDB文档。所需的结构如下: { “id”:ID(值...


空手道 DSL - 我在使用正则表达式验证十进制数时遇到问题

我有以下json: [ { “id”:1, “姓名”:“杰克”, “工资”:23.03 }, { “id”:2, “名字”:“卢克”, “工资”:0.00 ...


某些 HTML 实体代码未被评估

我有一个从数据库传递信息的视图: defserve_article(请求,id): served_article = Article.objects.get(pk=id) # 去掉新行和制表符 文章_片段...


当某些 id 的行数多于其他 id 时,按 id 从数据帧中抽取样本行

这是非常基本的,但我在网上找不到答案。我使用 R 并有一个像这样的数据集(但更大): 设置.种子(123) 编号<-c(1,1,1,2,2,3,3,3,3,3,4,5,5,6,6,6) week<-c(1,2,3,1,2,1,2,3,4...


如何根据交易类型加载关系模型总和?

我创建了两个模型 包含字段 id、名称、分行的银行 交易ID、来源、金额、类型 银行模型包含关系 这里的来源是银行表格中的 id 公共函数交易() { ...


谷歌脚本。获取包含部分字符串的数组

我有一个电子表格,其中 1 个单元格中有以下链接: https://drive.google.com/open?id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,https://drive.google.com/open?id=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 我...


查找中间是否存在值并检查 DAX+Power BI 末尾是否存在特定值

有如下数据: |id|已创建|花费时间|状态|索引|是列名 如何在 DAX 中查找状态为 P1 或 P2 的 id 以及状态以 P3 或 P4 结尾的 id? 结果...


Spring Boot中无法通过GET方法获取图像?

这是我的实体类 @ToString @数据 @实体 公开课产品{ @ID @GenerateValue(策略 = GenerationType.IDENTITY) 私有 int id; 私有字符串名称; 私人


© www.soinside.com 2019 - 2024. All rights reserved.