BackboneJS – 模型轉義



描述

該函式幾乎與 get 函式 相同,但會返回模型屬性的 HTML 轉義版本。

語法

model.escape(attribute)

引數

attribute - 屬性定義已建立模型的屬性。

<!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();
         var person = new Person();
         person.set({name: "John"});
         document.write(person.escape("name"));
      </script>
         
   </head>
   <body></body>
</html>

輸出

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

  • 將以上程式碼儲存在 escape.htm 檔案中。

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

backbonejs_model.htm
廣告
© . All rights reserved.