Backbone / chaplinJS:如何检查对象中的密钥存在

时间:2017-01-17 15:03:24

标签: backbone.js chaplinjs

{
                  "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"可用与否。

1 个答案:

答案 0 :(得分:4)

如果结果不是_.findWhere(yourObject.providerProperties, {key: "numOfRooms"});,那么您可以使用undefined这样的下划线方法findWhere