我将数据作为包含客户端各种详细信息的对象接收到我的172.30.58.XXX
。我有以下型号
$scope
在我的函数中,我希望确保每个键都有一个值,并且没有任何内容未定义。
我以为我可以使用client.name
client.email
client.programme
所以请仔细检查每一个并在if语句中检查未定义但是这不起作用。
例如:
||
其次我想在错误消息中使用一个变量,以便我可以将它定制为未定义的值。
答案 0 :(得分:1)
你没有将$ scope附加到变量。
使用此
$scope.addClient = function(newClient) {
if(!newClient){
$rootScope.$emit('errorEvent',
{"message" : "You must enter some client name"});
}
else if(!$scope.newClient.name || !scope.newClient.email) {
$rootScope.$emit('errorEvent',{"message" : "You must enter some client name" });
}
}
或
$scope.addClient = function(newClient) {
if(newClient && (!$scope.newClient.name || !scope.newClient.email) || !newClient ){
$rootScope.$emit('errorEvent',
{"message" : "You must enter some client name"});
}
}
答案 1 :(得分:0)
我最终不得不这样做:
ReservationID FriendID TableNumber ReservationDate ReservationStatus
16 58767732 32 21/04/2015 17:06:54 False
17 -1 32 21/04/2015 17:10:41 False
18 -1 2 21/04/2015 17:17:23 False
2 58767732 3 04/04/2015 19:37:17 False
3 -1 7 04/04/2015 19:37:43 False
4 -1 5 04/04/2015 23:24:24 False
5 -1 31 05/04/2015 16:29:02 False
6 -1 6 05/04/2015 16:40:29 False 7 -1 6 05/04/2015 17:12:47 False
8 58767732 32 09/04/2015 16:24:00 False
9 -1 6 09/04/2015 16:25:03 False
很高兴接受建设性的批评/选项以减少此代码...