En este artículo, veremos el modelo backbone.js has() . El modelo backbone.js has() se utiliza para verificar si un atributo contiene valor o no. si el valor existe o no es un valor nulo, devolverá «verdadero», si es nulo, devolverá «falso».
Sintaxis :
Backbone.Model.has(attribute);
Parámetros : Acepta un parámetro:
- atributo: Especifica el atributo en un modelo.
Ejemplo 1 : compruebe si los atributos del libro modelo tienen valores o no utilizando el modelo has() .
HTML
<!DOCTYPE html> <html> <head> <script src= "https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"> </script> <script src= "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"> </script> <script src= "https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" 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>
Producción:
bookid is not-null? : false price is not-null? : false book_name is not-null? : false
Ejemplo 2: Comprueba si el libro modelo tiene valores o no.
HTML
<!DOCTYPE html> <html> <head> <script src= "https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"> </script> <script src= "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"> </script> <script src= "https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" 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>
Producción:
bookid is not-null? : true price is not-null? : true book_name is not-null? : true
Referencia: https://backbonejs.org/#Model-has
Publicación traducida automáticamente
Artículo escrito por sireeshakanneganti112 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA