小编Rya*_*P13的帖子

如何与react-query并行处理多个突变

我有一个自定义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因为我需要在突变成功时使某些查询无效。

javascript promise reactjs react-query promise.all

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

CSS粘性页脚的问题

我正在尝试实现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)

html css xhtml

10
推荐指数
2
解决办法
2万
查看次数

断言函数抛出Qunit的异常

我是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)

javascript jquery unit-testing qunit

10
推荐指数
1
解决办法
4974
查看次数

使用jQuery postMessage插件的iframe跨域消息传递

我正在尝试使用以下插件在子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)

我真的不明白为什么这不起作用,我迫切需要帮助!

iframe jquery postmessage jquery-plugins cross-domain

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

javaScript从单个值的数组返回一个新的配对值数组

可能重复:将
数组拆分为块

我试图将值数组转换为新的配对值数组.

例如,我需要转换:

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)

javascript arrays jquery multidimensional-array

8
推荐指数
2
解决办法
4245
查看次数

Next.js、TypeScript 和 tsconfig.json 'jsx' 属性被覆盖

运行开发服务器时,如何阻止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

typescript reactjs tsconfig next.js

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

小胡子用一系列对象模板化

我正在尝试模拟以下对象数组:

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)

等等但不是两者兼而有之.

链接到这个问题的小提琴:

http://jsfiddle.net/AtJDa/

javascript jquery templates mustache

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

通过iframe查看的网站上的响应式设计

我正在开发一个将部署到Facebook的应用程序,因此可以从Facebook的chrome内部的iframe查看.

我有一些基本的媒体查询,以设置的视口大小线性化内容.

当在本地浏览器中查看该站点时,媒体查询工作正常,但在Facebook的chrome中进行测试时,它们无法正常工作.

我假设iframe的子节点未检测到视口的大小调整,因此媒体查询将不起作用.有没有办法让这个工作?

css iframe facebook-iframe media-queries responsive-design

6
推荐指数
1
解决办法
4873
查看次数

React Material UI OutlinedInput 不显示错误消息

我使用 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并显示错误帮助消息吗?

javascript typescript reactjs material-ui

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

将jQuery转换为原始JS-在h1之后插入p元素

关于如何将这个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 jquery

5
推荐指数
0
解决办法
4791
查看次数