1 | string .Join( "" , Enumerable.Repeat< string >( "a" , 8).ToArray());</ string > |
The code above repeat "a" 8 times and returns "aaaaaaaa".
1 | string .Join( "" , Enumerable.Repeat< string >( "a" , 8).ToArray());</ string > |
1 | Sitecore.Data.ID.IsNullOrEmpty(myID) |
var cars = [
{id: "F001", make: "Ford", model: "Fiesta",
colors: [
{id: 1, name: "Red"},
{id: 2, name: "Blue"}
]
},
{id: "T001", make: "Toyota", model: "Corolla",
colors: [
{id: 1, name: "Red"},
{id: 3, name: "Silver"}
]
},
{id: "T002", make: "Toyota", model: "Yaris",
colors: [
{id: 1, name: "Red"},
{id: 3, name: "Silver"},
{id: 4, name: "White"}
]
}
];
var toyotaCars = Enumerable.from(cars)
.where("c=> c.make == 'Toyota'");
var blueCars = Enumerable.from(cars)
.where("c=> c.colors.name == 'Blue'");
.where(function(c) {return (c.colors.name == 'Blue');})
Unfortunately this is not how it works and you will get nothing. Obviously linq.js is trying to work as close as to .NET LINQ but nothing is perfect. So to achieve what we want is the following:
var blueCars = Enumerable.from(cars)
.where(function(o) {
return (Enumerable.from(o.colors)
.where("c => c.name == 'Blue'").any());
});
Here you go, we will get Ford Fiesta!
Subscribe to:
Posts (Atom)