BackboneJS - 檢視擴充套件



說明

它擴充套件 Backbone.View 類來建立一個自定義檢視類。

語法

Backbone.View.extend(properties, classProperties)

引數

  • properties − 它為檢視類提供例項屬性。

  • classProperties − 附加到檢視的建構函式上的 classProperties。

示例

<!DOCTYPE html>
<html>
   <head>
      <title>View Example</title>
      <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">
         
         //'ViewDemo' is a name of the view class
         var ViewDemo = Backbone.View.extend ({

            //This function is called when the view is instantiated
            initialize:function() {
               document.write('Welcome to Tutorialspoint!!!');
            }
         });

         //'myview' is an instance of the view 'ViewDemo'
         var myview = new ViewDemo();
      </script>
      
   </body>
</html>

輸出

讓我們執行以下步驟,瞭解以上程式碼是如何工作的 −

  • extend.htm 檔案中儲存上述程式碼。

  • 在瀏覽器中開啟此 HTML 檔案。

backbonejs_view.htm
廣告
© . All rights reserved.