Не имеет ничего общего с ES6, но вам следует упростить ваше состояние с
(A && ¬Y) || (B && ¬X) || (A && B && X && Y)
до
(A || ¬X) && (B || ¬Y)
. Я бы также рекомендовал использовать some
вместо map
+ includes
. Оба эти изменения сделают ваш код более удобным для чтения и более эффективным:
filteredClasses() {
const {gradeFilter, subjectFilter} = this;
return _.flatMap(this.classes).filter(x =>
x.name === this.selectedClass.name
|| (!gradeFilter.length || gradeFilter.some(el => el.value === x.grade))
&& (!subjectFilter.length || subjectFilter.some(el => el.value === x.subjectId))
);
}
Потомки должны работать абсолютно прекрасные. Вот пример:
using System;
using System.Xml.Linq;
class Test
{
static void Main()
{
string xml = @"
<root>
<child id='1'/>
<child id='2'>
<grandchild id='3' />
<grandchild id='4' />
</child>
</root>";
XDocument doc = XDocument.Parse(xml);
foreach (XElement element in doc.Descendants("grandchild"))
{
Console.WriteLine(element);
}
}
}
Результаты:
<grandchild id="3" />
<grandchild id="4" />
Потомки сделают точно, в чем Вы нуждаетесь, но уверены, что включали имя пространства имен вместе с именем элемента. При исключении его Вы, вероятно, получите пустой список.
Пример, указывающий пространство имен:
String TheDocumentContent =
@"
<TheNamespace:root xmlns:TheNamespace = 'http://www.w3.org/2001/XMLSchema' >
<TheNamespace:GrandParent>
<TheNamespace:Parent>
<TheNamespace:Child theName = 'Fred' />
<TheNamespace:Child theName = 'Gabi' />
<TheNamespace:Child theName = 'George'/>
<TheNamespace:Child theName = 'Grace' />
<TheNamespace:Child theName = 'Sam' />
</TheNamespace:Parent>
</TheNamespace:GrandParent>
</TheNamespace:root>
";
XDocument TheDocument = XDocument.Parse( TheDocumentContent );
//Example 1:
var TheElements1 =
from
AnyElement
in
TheDocument.Descendants( "{http://www.w3.org/2001/XMLSchema}Child" )
select
AnyElement;
ResultsTxt.AppendText( TheElements1.Count().ToString() );
//Example 2:
var TheElements2 =
from
AnyElement
in
TheDocument.Descendants( "{http://www.w3.org/2001/XMLSchema}Child" )
where
AnyElement.Attribute( "theName" ).Value.StartsWith( "G" )
select
AnyElement;
foreach ( XElement CurrentElement in TheElements2 )
{
ResultsTxt.AppendText( "\r\n" + CurrentElement.Attribute( "theName" ).Value );
}