當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Backbone.js model.changedAttributes()用法及代碼示例

Backbone.js changedAttributes 模型返回自上次設置以來已更改的模型屬性的哈希值。如果沒有屬性,則為 false。

用法:

model.changedAttributes(attributes)

參數說明:

attributes:屬性定義模型的屬性。

讓我們舉個例子。

看這個例子:

<!DOCTYPE html>
   <head>
      <title>changedAttributes 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">
      var values = new Backbone.Model({
         name1:'Amar',
         name2:'Akbar',
         name3:'Anthony'
      });
      values.on('change', function() {
         document.write("The changed attributes are:");
         document.write(JSON.stringify(values.changedAttributes()));
      });
      values.set({
         name1:'Peter',
         name2:'Mark'
      });
   </script>
   </body>
</html>

輸出:

將上述代碼保存在 changedattributes.html 文件中,並在新瀏覽器中打開此文件。

BackboneJS ChangedAttributes Model



相關用法


注:本文由純淨天空篩選整理自 Backbone.js model.changedAttributes()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。