• <legend id='46U89'><style id='46U89'><dir id='46U89'><q id='46U89'></q></dir></style></legend>
  • <i id='46U89'><tr id='46U89'><dt id='46U89'><q id='46U89'><span id='46U89'><b id='46U89'><form id='46U89'><ins id='46U89'></ins><ul id='46U89'></ul><sub id='46U89'></sub></form><legend id='46U89'></legend><bdo id='46U89'><pre id='46U89'><center id='46U89'></center></pre></bdo></b><th id='46U89'></th></span></q></dt></tr></i><div id='46U89'><tfoot id='46U89'></tfoot><dl id='46U89'><fieldset id='46U89'></fieldset></dl></div>

    • <bdo id='46U89'></bdo><ul id='46U89'></ul>

    <small id='46U89'></small><noframes id='46U89'>

    <tfoot id='46U89'></tfoot>

      1. 量角器中的计数()与长度

        时间:2023-06-15
            <tbody id='YP3IO'></tbody>
        • <legend id='YP3IO'><style id='YP3IO'><dir id='YP3IO'><q id='YP3IO'></q></dir></style></legend>
          1. <tfoot id='YP3IO'></tfoot>

              <small id='YP3IO'></small><noframes id='YP3IO'>

              • <bdo id='YP3IO'></bdo><ul id='YP3IO'></ul>

                1. <i id='YP3IO'><tr id='YP3IO'><dt id='YP3IO'><q id='YP3IO'><span id='YP3IO'><b id='YP3IO'><form id='YP3IO'><ins id='YP3IO'></ins><ul id='YP3IO'></ul><sub id='YP3IO'></sub></form><legend id='YP3IO'></legend><bdo id='YP3IO'><pre id='YP3IO'><center id='YP3IO'></center></pre></bdo></b><th id='YP3IO'></th></span></q></dt></tr></i><div id='YP3IO'><tfoot id='YP3IO'></tfoot><dl id='YP3IO'><fieldset id='YP3IO'></fieldset></dl></div>
                  本文介绍了量角器中的计数()与长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  根据文档,有两种方法可以获取 ElementArrayFinder 中有多少元素(element.all() 调用的结果):

                  • $$(".myclass").length,记录在 这里:
                  <块引用>

                  ...数组的length等于ElementArrayFinder找到的元素的length,每个结果代表执行的结果对元素的操作.

                  • $$(".myclass").count(),记录在 这里:
                  <块引用>

                  计算ElementArrayFinder所代表的元素个数.

                  这两种方法有什么区别,应该首选哪一种?

                  解决方案


                  $$(".myclass").length

                  需要解决 promise 以正确获取元素的长度.

                  //工作$$(".myclass").then(function(items){项目长度;});//不工作$$(".myclass").length;

                  <小时>

                  $$(".myclass").count()

                  $$('.myclass').length 的包装器,它本身就是一个 Promise,不需要像 .length 那样解析 Promise

                  $$(".myclass").count();

                  <小时><块引用>

                  应该首选哪一个?

                  除非在定位$$(".myclass").then(function(items){...})时涉及到一些复杂的业务,那么items.length 将提供更好的性能.

                  否则 $$(".myclass").count() 应始终使用.

                  According to the documentation, there are 2 ways to get how many elements are inside the ElementArrayFinder (the result of element.all() call):

                  • $$(".myclass").length, documented here:

                  ...the array has length equal to the length of the elements found by the ElementArrayFinder and each result represents the result of performing the action on the element.

                  • $$(".myclass").count(), documented here:

                  Count the number of elements represented by the ElementArrayFinder.

                  What is the difference between these two methods and which one should be preferred?

                  解决方案


                  $$(".myclass").length

                  Need to resolve the promise to get the length of element correctly.

                  // WORK
                  $$(".myclass").then(function(items){
                    items.length;
                  });
                  
                  // DOES NOT WORK
                  $$(".myclass").length; 
                  


                  $$(".myclass").count()

                  A wrapper for $$('.myclass').length which being a promise itself and doesn't require to resolve promise like .length

                  $$(".myclass").count(); 
                  


                  which one should be preferred?

                  Unless there some complex business when locating $$(".myclass") and .then(function(items){...}) involved then items.length will give better performance.

                  Otherwise $$(".myclass").count() should always be used.

                  这篇关于量角器中的计数()与长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:量角器切换到上一个选项卡 下一篇:使用预期条件时未定义的属性“绑定"

                  相关文章

                  <small id='e7nGb'></small><noframes id='e7nGb'>

                  <legend id='e7nGb'><style id='e7nGb'><dir id='e7nGb'><q id='e7nGb'></q></dir></style></legend>

                        <bdo id='e7nGb'></bdo><ul id='e7nGb'></ul>

                      <i id='e7nGb'><tr id='e7nGb'><dt id='e7nGb'><q id='e7nGb'><span id='e7nGb'><b id='e7nGb'><form id='e7nGb'><ins id='e7nGb'></ins><ul id='e7nGb'></ul><sub id='e7nGb'></sub></form><legend id='e7nGb'></legend><bdo id='e7nGb'><pre id='e7nGb'><center id='e7nGb'></center></pre></bdo></b><th id='e7nGb'></th></span></q></dt></tr></i><div id='e7nGb'><tfoot id='e7nGb'></tfoot><dl id='e7nGb'><fieldset id='e7nGb'></fieldset></dl></div>
                      <tfoot id='e7nGb'></tfoot>