我有一个自定义useMutation钩子:
const {
status: updateScheduleStatus,
reset: updateScheduleReset,
mutateAsync: updateSchedule,
} = useUpdateSchedule(queryClient, jobId as string);
Run Code Online (Sandbox Code Playgroud)
据我所知,它设置了突变,但是如果我想做多个并行突变,我将如何使用它?
我尝试实现以下内容,但突变在到达线路之前执行Promise.all(mutations。
let mutations: Array<any> = [];
schedulesForDeletion.forEach(async (schedule) => {
const resp = await monitoringService?.getSchedule(
schedule.schedule_id,
);
mutations.push(
updateSchedule({
monitoringService: monitoringService as MonitoringServiceClient,
schedule,
etag: resp?.type === "data" ? resp.headers.etag : "",
}),
);
});
console.dir(mutations);
await Promise.all(mutations);
Run Code Online (Sandbox Code Playgroud)
我会通过mutateAsync返回 a来Promise表示它们不会按顺序开火,但似乎会按顺序开火。
有没有办法处理这个问题,react-query或者我最好用 axios 来执行这个操作?这样做会很有用,react-query因为我需要在突变成功时使某些查询无效。
我正在尝试实现CSS粘性页脚.
问题是有一个内容DIV超出了它的容器,导致滚动条不可取,并且挂在页面div上的背景图像不会延伸文档的整个高度.
这是我的HTML:
<div id="page">
<div id="header">
<dl>
<dt>Header links -</dt>
<dd><a href="#">link 1</a></dd>
<dd><a href="#">link 2</a></dd>
<dd><a href="#">link 3</a></dd>
</dl>
</div>
<div id="content">
<p><a id="modal" href="popup.html" target="_blank">link to popup</a></p>
</div>
<div id="footer">
<dl>
<dt>Footer links -</dt>
<dd><a href="#">link 1</a></dd>
<dd><a href="#">link 2</a></dd>
<dd><a href="#">link 3</a></dd>
</dl>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是CSS:
/*--------------------------------------------------------------- global */
html,
body {
color:#969696;
font-size:100%;
height:100%;
}
body {
font:normal 200 70% Arial, Helvetica, Verdana, sans-serif;
}
a,
a:link,
a:visited,
a:hover,
a:active {
border-bottom:1px dashed #ff8400;
color:#ff8400; …Run Code Online (Sandbox Code Playgroud) 我是Qunit和单元测试的新手.
我试图找出测试以下功能的内容和方法.它目前没有做太多但我想断言如果我传递错误值的错误值:
function attrToggle (panel, attr) {
'use strict';
if (!panel) { throw new Error('Panel is not defined'); }
if (!attr) { throw new Error('Attr is not defined'); }
if (typeof panel !== 'string') { throw new Error('Panel is not a string'); }
if (typeof attr !== 'string') { throw new Error('Attr is not a string'); }
if (arguments.length !== 2) { throw new Error('There should be only two arguments passed to this function')}
};
Run Code Online (Sandbox Code Playgroud)
如果不满足任何这些条件,我该怎么断言会抛出错误?
我试着看看Qunit的'加注'断言但认为我误解了它.我的解释是,如果抛出错误,测试就会通过.
所以,如果我测试了这样的东西:
test("a test", …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下插件在子iframe和其父级之间进行通信:
http://benalman.com/projects/jquery-postmessage-plugin/
我可以按照示例将一条消息从孩子发布到父母而不是其他方式,我真的需要能够以两种方式进行交流.
父代码如下:
var origin = document.location.protocol + '//' + document.location.host,
src = origin + '/Custom/Ui/Baseline/html/iframe-data-cash.htm#' + encodeURIComponent(document.location.href);
$(function () {
var $holder = $('#iframe'),
height,
$iframe = $('<iframe src="' + src + '" id="data-cash-iframe" width="100%" scrolling="no" allowtransparency="true" seamless="seamless" frameborder="0" marginheight="0" marginwidth="0"></iframe>');
// append iframe to DOM
$holder.append($iframe);
});
$(window).load(function () {
$.postMessage(
'hello world',
src,
parent.document.getElementById('data-cash-iframe').contentWindow
);
});
Run Code Online (Sandbox Code Playgroud)
孩子的代码如下:
$(function () {
var parentURL = decodeURIComponent(document.location.hash.replace(/^#/, ''));
$.receiveMessage(
function (e) {
alert(e.data);
},
parentURL
);
});
Run Code Online (Sandbox Code Playgroud)
我真的不明白为什么这不起作用,我迫切需要帮助!
可能重复:将
数组拆分为块
我试图将值数组转换为新的配对值数组.
例如,我需要转换:
var arr = [1,2,3,4,5,6,7,8];
Run Code Online (Sandbox Code Playgroud)
成:
arr = [[1,2], [3,4], [5,6], [7,8]];
Run Code Online (Sandbox Code Playgroud)
我尝试使用jQuery的.map()方法,但这对我不起作用:
arr= $.map(arr, function(n, i){
return [n + ',' + n[ i + 1 ]];
});
Run Code Online (Sandbox Code Playgroud) 运行开发服务器时,如何阻止jsxNextJS 将属性从“react”覆盖为“preserve”?
我的tsconfig.json文件:
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"exclude": [
"node_modules"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
]
}
Run Code Online (Sandbox Code Playgroud)
AFAIK jsx 选项必须是将我的文件react编译为.tsxjsx
我正在尝试模拟以下对象数组:
var arr = [{name:"Ryan Pays", url:"http://www.ryanpays.com"}, {name:"foo", url:"http://www.google.com"}];
Run Code Online (Sandbox Code Playgroud)
我将该数组转换为如下对象:
arr = $.extend({}, arr);
Run Code Online (Sandbox Code Playgroud)
这给了我以下对象:
{
0:{name:"Ryan Pays", url:"http://www.ryanpays.com"},
1:{name:"foo", url:"http://www.google.com"}
}
Run Code Online (Sandbox Code Playgroud)
使用Mustache我想使用以下模板枚举该对象:
var template = "<h4>Your friends' choices</h4>" +
"<ul>" +
"<li>" +
"<p><strong>{{name}}</strong> likes <a href='{{url}}'>this</a></p>" +
"</li>" +
"</ul>";
var html = Mustache.to_html(template, displayData);
$('.choices').html(html);
Run Code Online (Sandbox Code Playgroud)
我似乎无法做到这一点.我可以得到第一个结果像这样打印:
var html = Mustache.to_html(template, displayData[0]);
Run Code Online (Sandbox Code Playgroud)
等等但不是两者兼而有之.
链接到这个问题的小提琴:
我正在开发一个将部署到Facebook的应用程序,因此可以从Facebook的chrome内部的iframe查看.
我有一些基本的媒体查询,以设置的视口大小线性化内容.
当在本地浏览器中查看该站点时,媒体查询工作正常,但在Facebook的chrome中进行测试时,它们无法正常工作.
我假设iframe的子节点未检测到视口的大小调整,因此媒体查询将不起作用.有没有办法让这个工作?
我使用 React 和 Material UI 来显示概述的输入。error我可以让它显示道具设置有错误,但是当我尝试添加我的消息作为道具true时出现问题:helperText
<OutlinedInput
margin="dense"
value=""
placeholder="my placeholder"
error
helperText="There has been an error" // Property 'helperText' does not exist on type 'IntrinsicAttributes & OutlinedInputProps'
/>
Run Code Online (Sandbox Code Playgroud)
有什么方法可以同时使用OutlinedInput并显示错误帮助消息吗?
关于如何将这个jQuery转换为香草JS的任何想法:
$('.section > h1').after('<p>This paragraph was inserted with jQuery</p>');
Run Code Online (Sandbox Code Playgroud)
我是jQuery的新手,甚至是香草JS的新手。
据我所知:
var newP = document.createElement('p');
var pTxt = document.createTextNode('This paragraph was inserted with JavaScript');
var header = document.getElementsByTagName('h1');
Run Code Online (Sandbox Code Playgroud)
不知道从这里去哪里?
javascript ×6
jquery ×5
reactjs ×3
css ×2
iframe ×2
typescript ×2
arrays ×1
cross-domain ×1
html ×1
material-ui ×1
mustache ×1
next.js ×1
postmessage ×1
promise ×1
promise.all ×1
qunit ×1
react-query ×1
templates ×1
tsconfig ×1
unit-testing ×1
xhtml ×1