角度1:具有多个条件的多个条件或如果其他条件为真,如何排除条件

时间:2016-10-04 16:57:05

标签: javascript angularjs

现在我已经创建了一个额外的范围来保持一个条件。

<div ng-repeat="(key, resultLinks) in resultGroup.resultLinks">
    <div ng-if="key < 4 || viewMore" ng-repeat="(subKey, linksWrap) in resultLinks.linksWrap">
        <span ng-if="wWidth > 568 || subKey == 0" ng-repeat="links in linksWrap.links">
                {{links.linkName}}
        </span>
    </div>
</div>

您如何更改它以便所有条件都在一个div中。即:ng-if =&#34;(键&lt; 4 || viewMore)|| (wWidth> 568 || subKey == 0)&#34; (像这样,但不完全)。如果另一个条件属实,可能会以某种方式排除一个条件吗?

2 个答案:

答案 0 :(得分:1)

  

如果另一个条件成立,是否有可能以某种方式排除一个条件?

这正是OR((key < 4 || viewMore))运算符正在做的事情。如果true(wWidth > 568 || subKey == 0)则不会更进一步, <div ng-if="(key < 4 || viewMore) || (wWidth > 568 || subKey == 0)" ng-repeat="(subKey, linksWrap) in resultLinks.linksWrap"> <span ng-repeat="links in linksWrap.links"> {{links.linkName}} </span> </div> 将无法执行。

这应该有效:

<div ng-if="isVisible(key, subKey)"... >

你可以看到它看起来很丑陋。我会将逻辑移出模板:

$scope.isVisible = function(key, subKey){  
    return (key < 4 || $scope.viewMore) || ($scope.wWidth > 568 || subKey == 0)
}

控制器中的某处:

Private Sub Test_GetInetHeaders()

Dim olNewmail As mailItem
Dim strHeader As String
Dim olItem As mailItem

Set olItem = ActiveInspector.currentItem
strHeader = GetInetHeaders(olItem)

Set olNewmail = CreateItem(olMailItem)
olNewmail.body = strHeader
olNewmail.Display

MsgBox "Truncated string if limit exceeded: " & strHeader

ExitRoutine:
    Set olItem = Nothing
    Set olNewmail = Nothing

End Sub

Function GetInetHeaders(olkMsg As outlook.mailItem) As String
    ' Purpose: Returns the internet headers of a message.'
    ' Written: 4/28/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: 2007'
    Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
    Dim olkPA As outlook.propertyAccessor
    Set olkPA = olkMsg.propertyAccessor
    GetInetHeaders = olkPA.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS)
    Set olkPA = Nothing
End Function

答案 1 :(得分:1)

这是你正在寻找的吗?

(key < 4 || viewMore) && (wWidth > 568 || subKey == 0)
相关问题