BackboneJS - Model Id



描述

它惟一地標識模型實體,該實體可以在建立或填充模型時或在模型儲存在伺服器上時手動設定。

語法

model.id

示例

<!DOCTYPE html>
<html>
   <head>
      <title> Model 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>
      
      <script type = "text/javascript">
         var  Person = Backbone.Model.extend ({
            defaults: {
               id: 26
            }
         });
         var person = new Person();
         document.write("Id of the model: ", person.get('id'));
      </script>
      
   </head>
   <body></body>
</html>

輸出

讓我們執行以下步驟來了解上面的程式碼是如何工作的 -

  • 將上面的程式碼儲存在 id.htm 檔案中。

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

backbonejs_model.htm
廣告
© . All rights reserved.