Saturday, November 16, 2024
Google search engine
HomeLanguagesJavascriptBackbone.js has Model

Backbone.js has Model

In this article, we will see the Backbone.js has() model. The Backbone.js has() model is used to check if an attribute contains value or not. if the value exists or it’s a not-null value, it will return “true”, if it is null, it will return “false”.

Syntax:

Backbone.Model.has(attribute);

Parameters: It accepts one parameter:

  • attribute: It specifies the attribute in a model.

Example 1: Check whether the model book attributes have values or not by using has() model.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>    
</head>
  
<body>
    <script type="text/javascript">  
        var Books = Backbone.Model.extend();  
        var book = new Books({bookid:null,price:null,book_name:null}); 
             
        document.write(" bookid is not-null? : ",book.has('bookid'));
        document.write("<br>");
        document.write(" price is not-null? : ",book.has('price'));
        document.write("<br>");
        document.write(" book_name is not-null? : ",book.has('book_name')); 
    </script
</body>
</html>


Output:

bookid is not-null? : false
price is not-null? : false
book_name is not-null? : false

Example 2: It checks whether the model book has values or not.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>    
</head>
  
<body>
    <script type="text/javascript">  
        var Books = Backbone.Model.extend();  
        var book = new Books({bookid:6,price:4555,book_name:'php'}); 
             
        document.write(" bookid is not-null? : ",book.has('bookid'));
        document.write("<br>");
        document.write(" price is not-null? : ",book.has('price'));
        document.write("<br>");
        document.write(" book_name is not-null? : ",book.has('book_name'));
    </script
</body>
</html>


Output:

bookid is not-null? : true
price is not-null? : true
book_name is not-null? : true

Reference: https://backbonejs.org/#Model-has

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments