是否可以以倒计时样式格式化秒?例如,如果我有var seconds = 3662,我该如何显示:1 hour 1 minute 2 seconds。
我尝试使用,formatDistanceStrict(3662)但这只是打印小时:1 hour。
是否有内置方法来显示分钟和秒?我不想写 100 行代码来让它工作(就像互联网上的其他例子一样)
我把这个难看的句子用||.
const a = "they *have* a* car* sold. ||They* eat* the * good * stuff";
Run Code Online (Sandbox Code Playgroud)
我怎样才能用*或||符号分割给定的字符串,以便我们得到这个结果:
['they', 'have','a', 'car', 'sold', 'they', 'eat', 'the ', 'good ', 'stuff'];
Run Code Online (Sandbox Code Playgroud)
我不介意间距问题,我希望通过这个或那个功能进行拆分。
注意:我们可以简单地使用 a 来实现这一点,map但我想知道是否有正则表达式之类的解决方案!
我想使用我的架构在其他字段的基础上验证一个字段。就像,如果 carType 是“SUV”,则最大“noOfPassengers”应该是 6,否则是 4。但是,它没有验证这种情况,我既无法调试它,也无法在控制台中收到任何错误。
const validationSchema = yup.object().shape({
location: yup
.string()
.required('location is required'),
destination: yup
.string()
.required('Destination is required'),
carType: yup
.string(),
noOfPassengers: yup
.string()
.when('carType', {
is: value => value && value === "SUV",
then: yup
.string()
.max(6, 'Max 6 passengers are required'),
otherwise: yup
.string()
.max(4, 'Max 4 passengers are required'),
}),
});
Run Code Online (Sandbox Code Playgroud) 我有一个数据表,可使用ajax从数据库中获取记录。我想编辑工具提示像添加jQuery的数据表编辑器扩展到数据表,但免费。有没有插件可以做到这一点?如果没有,有人可以帮助我手动执行此操作吗?
这是我的JavaScript代码:
$('#table_id').DataTable({
"serverSide": true,
"processing": true,
"ajax": function (data, callback, settings) {
$.ajax({
url: '/some url',
type: 'GET',
data: data,
success: function (data) {
console.log(data)
}
});
},
"columns": [{
"title": "edit",
"data": null,
"className": "center",
"defaultContent": '<a href = "" class = "editor_edit"> Edit </a> / <a href = "" class = "editor_remove"> Delete </a>'
}, {
"title": "name",
"data": "name"
}, {
"title": "id",
"data": "id"
},
]
});
Run Code Online (Sandbox Code Playgroud) 我想将字符串日期转换2020-06-21T10:15:00Z 为21-06-2020 10:15?
我这样做就像分成两部分并从时间中删除最后 4 个字符:
const newDate = date.split('T');
const time = newDate.length >= 1 ? newDate[1].slice(3, -1) : '';
Run Code Online (Sandbox Code Playgroud)
我正在寻找更好的解决方案?
我有一个像下面这样的数组,其中有两种类型的数据,file或者folder. 我只想过滤file类型数据。
let data = [
{
"id": 3,
"type": "file",
"url": "www.first.com"
}, {
"id": 4,
"type": "file",
"url": "www.second.com"
}, {
"id": 5,
"type": "folder",
"items": [
{
"id": 6,
"type": "file",
"url": "www.third.com"
}
]
}
];
Run Code Online (Sandbox Code Playgroud)
想要的结果是
[
{
"id": 3,
"type": "file",
"url": "www.first.com"
}, {
"id": 4,
"type": "file",
"url": "www.second.com"
}, {
"id": 6,
"type": "file",
"url": "www.third.com"
}
]
Run Code Online (Sandbox Code Playgroud)
注意:可以有多个级别,例如文件夹内的项目,也可以有另一个文件夹
任何帮助,将不胜感激。谢谢!
任何本机替代品:
const colorArray = ['red', 'green', 'green', 'blue', 'purple', 'red', 'red', 'black'];
Run Code Online (Sandbox Code Playgroud)
到:
Object {
"red": 3,
"green": 2,
"blue": 1,
"purple": 1,
"black": 1
}
Run Code Online (Sandbox Code Playgroud)
在javascript中??
const colorArray = ['red', 'green', 'green', 'blue', 'purple', 'red', 'red', 'black'];
Run Code Online (Sandbox Code Playgroud)
感谢您的宝贵努力和时间!!
javascript arrays duplicates categorization categorical-data
我知道数据点及其值被描述为数组,speed并且power
speed = [2, 6, 8, 10, 12]
power = [200, 450, 500, 645, 820],
Run Code Online (Sandbox Code Playgroud)
我想估计与源数组(2 到 12)中未列出的速度值(例如 7)相对应的功率值。
即我正在寻找一种方法来执行插值
好的,我是 React 的新手,需要帮助阅读/引用 HTML 元素数据属性甚至 HTML 标签中的内容 - 通常使用纯 JS(这就是我在 React 应用程序中所做的)我是这样读的:
const postRow = document.getElementById(tableRowId);
;
const author = postRow.getElementsByTagName('td')[0].getAttribute('data-fieldvalue');
const title = postRow.getElementsByTagName('td')[1].getAttribute('data-fieldvalue');
const description = postRow.getElementsByTagName('td')[2].getAttribute('data-fieldvalue');
Run Code Online (Sandbox Code Playgroud)
我有一个名为 Table 的功能组件,我像这样使用它:
<Table
headers={this.state.postsHeaders}
rows={this.state.posts}
editable={this.state.editable}
deletable={this.state.deletable}
onUpdateIconClicked={this.toggleUpdatePostModalView}
onDeleteIconClicked={this.toggleDeletePostModalView}
/>
Run Code Online (Sandbox Code Playgroud)
其中 rows 属性是我正在检索的数据axios。我的表生成了多tr > td行查找。我为每一行都有一个“编辑”CTA,点击后我会打开一个模式,在那里我传递要为每一行编辑的数据。CTA 的 Onclick 调用了这个工作正常的函数:
toggleUpdatePostModalView = (postId, tableRowId) => {
// toggle the confirm delete post view
let showUpdatePostModal = !this.state.showUpdatePostModal;
// when postId and tableRowId are both null that means
// …Run Code Online (Sandbox Code Playgroud) 我想在<p>标签内的文本发生更改时触发事件。我想使用change(),但我意识到它适用于表单输入元素。
$("#click").click(function() {
$('p').html("done");
});Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<p> Hello </p>
</div>
<button id="click">click to change</button>Run Code Online (Sandbox Code Playgroud)
不确定我需要更改什么,但我在不同的 div 中有两个具有相同类名的元素,并且我不确定如何填充它们。
HTML:
<div>
<a class="this-thing">Text</a>
</div>
<div>
<a class="this-thing">Text</a>
</div>
Run Code Online (Sandbox Code Playgroud)
JS
const text = document.querySelectorAll(".this-thing");
text.innerHTML +='Add'
Run Code Online (Sandbox Code Playgroud)
不知道为什么当我有一个实例时它会起作用,但是如果我向该类添加另一个元素,this-thing它就根本不起作用。
javascript ×11
arrays ×2
jquery ×2
reactjs ×2
ajax ×1
datatables ×1
date ×1
date-fns ×1
duplicates ×1
formik ×1
html ×1
laravel ×1
time-format ×1
typescript ×1
yup ×1