BackboneJS - Model 銷燬



說明

它透過使用 Backbone.sync 方法銷燬或從伺服器中刪除 Model,而該方法委派了 HTTP“delete”請求。

語法

model.destroy(options)

引數

options - 包括一些引數,如 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">
         Backbone.sync = function(method, model) {
            document.write(method + ": " + JSON.stringify(model)+"<br>");
            model.set('id',1);
         };
         var details = new Backbone.Model ({
            Country:"India",
            Name:"Sachin Tendulkar"
         });
         details.save();
         details.destroy();
      </script>
      
   </head>
   <body></body>
</html>

輸出

讓我們執行以下步驟,檢視上述程式碼如何工作的 -

  • 將上述程式碼儲存在 destroy.htm 檔案中。

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

backbonejs_model.htm
廣告
© . All rights reserved.