ion-col:属性col- *不应用null值而不是false

时间:2018-04-20 13:49:08

标签: html typescript ionic3 angular5

  

我想使用col- *属性动态设置列宽。

     

Demo

当我设置[attr.col-3]="false"时,无论如何都应用了宽度(col-3)。

要不应用col-3,我必须以这种方式将属性设置为null[attr.col-3]="false ? true : null"

当我的条件变量是布尔值时,有没有办法避免添加额外的代码?

应用属性col-3

<ion-col [attr.col-2]="true" [attr.col-3]="false">col-2</ion-col>

未应用属性col-3

<ion-col [attr.col-2]="true" [attr.col-3]="false ? false : null">col-2</ion-col>

1 个答案:

答案 0 :(得分:0)

不,没有其他方法可以有条件地删除属性,然后将其设为null。所以你必须编写那些额外的代码行。这将是必要的:

# Abstract Data Type: Doubly Linked List
# A doubly linked list dll supports
# dll.is_empty()
# len(dll)
# dll.insert_between(e, predecessor, successor)
# dll.delete_node(a_node): should not delete the header and trailer nodes

# We will implement this class as an abstract class
# Meaning it is meant to be inherited by other data structures rather than
# instantiated directly



class _DoublyLinkedList(object):
    class _Node:
        # nested _Node class------------------------------------------------
        __slots__ = '_element', '_prev', '_next'

        def __init__(self, element, previous, next_):  # next is a reserved 
            # word, hence underscore
            self._element = element
            self._prev = previous
            self._next = next_

    class Empty(Exception):
        pass
    #-----------------------------------------------------------------------
    def __init__(self):
        self.header = self._Node(None, None, None)
        self.trailer = self._Node(None, None, None)
        self.header._next = self.trailer
        self.trailer._prev = self.header
        self.size = 0

    def __len__(self):
        return self.size

    def is_empty(self):
        return self.size == 0

    def insert_between(self, e, predecessor, successor):
        new_node = self._Node(e, predecessor, successor)
        predecessor._next = new_node
        successor._prev = new_node
        self.size += 1
        return new_node

    def delete_node(self, a_node):
        """Should not delete sentinels."""
        # Error management POTENTIAL EXAM QUESTION so that it doesn't delete 
        # sentinels
        # if a_node == self.header or a_node == self.trailer:
        #     return Err

        prev_ = a_node._prev
        next_ = a_node._next
        prev_._next = next_
        next_._prev = prev_
        temp = a_node._element
        a_node._prev = a_node._next = None
        self.size -= 1
        return temp

    def middle(self):
        n = self.header._next
        m = self.trailer._prev
        if n == self.trailer:
            return None
        while n != m:
            n = n._next
            m = m._next
        return m

    def printLinkedList(self):
        node = self.header
        while node is not None:
            print(node._next)
            node = node._next

    def reverse(self):
        current = self.header

        while current is not None:
            temp = current._prev
            current._prev = current._next
            current._next = temp
            current = current.prev

if __name__ == "__main__":
    pl = PositionalList()

    # Add 2, 3, 4, 1
    p2 = pl.add_first(2)
    p3 = pl.add_after(p2, 3)
    p4 = pl.add_after(p3, 4)
    p1 = pl.add_after(p4, 1)

    pl.find(4)