Is it possible to data-bind visible to the negation (“!”) of a boolean ViewModel property?

前端 未结 8 964
清歌不尽
清歌不尽 2020-12-23 15:24

I\'d like to use a property on my ViewModel to toggle which icon to display without creating a separate computed property of the inverse. Is this possible?



        
相关标签:
8条回答
  • 2020-12-23 16:16

    When using an observable in an expression you need to access it as a function like:

    visible: !charted()

    0 讨论(0)
  • 2020-12-23 16:22

    You could use my switch/case binding, which includes case.visible and casenot.visible.

    <tbody data-bind="foreach: periods">
        <tr>
            <td data-bind="switch: true">
            <i class="icon-search" data-bind="case.visible: $else, click: $parent.pie_it"></i>
            <i class="icon-remove" data-bind="case.visible: charted, click: $parent.pie_it"></i>
            </td>
        </tr>
    </tbody>
    

    You could also have it as

            <i class="icon-search" data-bind="casenot.visible: charted, click: $parent.pie_it"></i>
            <i class="icon-remove" data-bind="case.visible: $else, click: $parent.pie_it"></i>
    
    0 讨论(0)
提交回复
热议问题