发布于 2015-08-14 15:14:57 | 133 次阅读 | 评论: 0 | 来源: 网络整理

它使用set()方法设置的属性后已更改的属性。

语法


model.changed

示例


<!DOCTYPE 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">
            Player = Backbone.Model.extend({
            defaults: {
               p_name: 'sachin',
               country: 'india'
            },
            initialize: function () {
               this.bind("change:p_name", function (model) {
                  var name = model.get("p_name");
                  var ctry = model.get("country");
               });
           }
           });
           var person = new Player();
           document.write("<b>Before changing the name attribute, its value is:</b> ", person.get("p_name"));
           person.set({ p_name: 'dhoni' });
           document.write("<br><b>After changing the name attribute, its value is:</b> ", person.get("p_name"));
         </script>
   </head>
   <body></body>
</html>

输出

让我们进行以下步骤来看看上面的代码工作:

  • 保存上述代码到文件changed.html

  • 打开浏览器这个HTML文件。

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务