我想声明此对象中的所有子对象都包含一个为true的open属性:
struct sockaddr_in from_addr;
socklen_t fromlen = sizeof(from_addr);
char from_ip[2048] = "";
int nbytes = 0;
// Receive until the peer shuts down the connection
do {
nbytes = recvfrom(ClientSocket, recvbuf, recvbuflen, 0, (sockaddr *) &from_addr, &fromlen);
InetNtop(AF_INET, &from_addr.sin_addr, from_ip, sizeof(from_ip));
if (nbytes > 0) {
printf("Received %d bytes from %s@%d", nbytes, from_ip, ntohs(from_addr.sin_port));
// Echo the buffer back to the sender
iSendResult = send(ClientSocket, recvbuf, nbytes, 0);
if (iSendResult == SOCKET_ERROR) {
printf("send failed with error: %d\n", WSAGetLastError());
closesocket(ClientSocket);
WSACleanup();
return 1;
}
printf("\tBytes sent: %d\n", iSendResult);
}
else if (nbytes == 0)
printf("Connection closing...\n");
else {
printf("recv failed with error: %d\n", WSAGetLastError());
closesocket(ClientSocket);
WSACleanup();
return 1;
}
fromlen = sizeof(from_addr);
} while (nbytes > 0);
现在我正在做:
var groups = {
'Group1': {
open: true,
entries: [...]
},
'Group2': {
open: true,
entries: [...]
},
'Group3': {
open: true,
entries: [...]
}
}
有没有可以简化这个的柴相匹配器。例如
angular.forEach(groups, function(group) {
expect(group.open).to.be.true;
})