Backbone/chaplinJS : 如何检查对象中是否存在键
Backbone/chaplinJS : How to check for key existence in object
{
"providerProperties": [
{
"key": "hotelnum",
"value": "123"
},
{
"key": "contract",
"value": "ABC"
},
{
"key": "Sequence",
"value": "1213"
},
{
"key": "lastFourDigit",
"value": "5454"
},
{
"key": "shop",
"value": "abc"
},
{
"key": "bookingEmailAddress",
"value": "abc@gmail.COM"
},
{
"key": "numOfRooms",
"value": "1"
}
}
Backbone/chaplinJS : 如何检查对象中是否存在键。
例如要检查密钥 "numOfRooms" 是否可用。
你可以使用下划线方法 findWhere
就像 _.findWhere(yourObject.providerProperties, {key: "numOfRooms"});
如果结果不是 undefined
那么它存在
{
"providerProperties": [
{
"key": "hotelnum",
"value": "123"
},
{
"key": "contract",
"value": "ABC"
},
{
"key": "Sequence",
"value": "1213"
},
{
"key": "lastFourDigit",
"value": "5454"
},
{
"key": "shop",
"value": "abc"
},
{
"key": "bookingEmailAddress",
"value": "abc@gmail.COM"
},
{
"key": "numOfRooms",
"value": "1"
}
}
Backbone/chaplinJS : 如何检查对象中是否存在键。 例如要检查密钥 "numOfRooms" 是否可用。
你可以使用下划线方法 findWhere
就像 _.findWhere(yourObject.providerProperties, {key: "numOfRooms"});
如果结果不是 undefined
那么它存在