我如何获得w2ui中所有对象的数组

时间:2018-10-15 17:33:37

标签: w2ui

我随后尝试操纵w2ui应用程序的菜单和选项卡。 为了实现通用解决方案,我向相关元素添加了一个附加属性(zndesktop)。现在,我正在寻找一种通用方法,该方法可以为我提供具有该属性的所有对象的数组。

当然,我可以对这样的查询进行硬编码。但是我在问是否有通用方法(例如w2ui.objects)将返回为应用程序创建的所有UI对象的数组(递归搜索)

1 个答案:

答案 0 :(得分:0)

w2ui对象实际上使用它们的 File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\branca\element.py", line 113, in add_to parent.add_child(self, name=name, index=index) AttributeError: 'str' object has no attribute 'add_child' 直接存储在全局w2ui对象中,直到销毁它们为止。

示例:如果您使用

创建网格
import eulerlib


def compute():
    DIGITS = 10

    primes = eulerlib.list_primes(eulerlib.sqrt(10**DIGITS))

    # Only valid if 1 < n <= 10^DIGITS.
    def is_prime(n):
        end = eulerlib.sqrt(n)
        for p in primes:
            if p > end:
                break
            if n % p == 0:
                return False
        return True


    ans = 0
    # For each repeating digit
    for digit in range(10):

        # Search by the number of repetitions in decreasing order
        for rep in range(DIGITS, -1, -1):
            sum = 0
            digits = [0] * DIGITS

            # Try all possibilities for filling the non-repeating digits
            for i in range(9**(DIGITS - rep)):

                # Build initial array. For example, if DIGITS=7, digit=5, rep=4, i=123, then the array will be filled with 5,5,5,5,1,4,7.
                for j in range(rep):
                    digits[j] = digit
                temp = i
                for j in range(DIGITS - rep):
                    d = temp % 9
                    if d >= digit:  # Skip the repeating digit
                        d += 1
                    if j > 0 and d > digits[DIGITS - j]:  # If this is true, then after sorting, the array will be in an already-tried configuration
                        break
                    digits[-1 - j] = d
                    temp //= 9

                else:
                    digits.sort()  # Start at lowest permutation

                    while True:  # Go through all permutations
                        if digits[0] > 0:  # Skip if the number has a leading zero, which means it has less than DIGIT digits
                            num = int("".join(map(str, digits)))
                            if is_prime(num):
                                sum += num
                        if not eulerlib.next_permutation(digits):
                            break

            if sum > 0:  # Primes found; skip all lesser repetitions
                ans += sum
                break

    return str(ans)


if __name__ == "__main__":
    print(compute())

然后您可以使用name$('#grid').w2grid({ name: 'my_grid', ... }); 来访问它。

当然,您也可以像其他任何JS对象一样迭代w2ui.my_grid对象(或更确切地说,它的属性)。

相关问题