• emberJS


    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <script src="http://localhost:81/js/jquery.min.js"></script>
    <script src="http://localhost:81/js/handlebars.js"></script>
    <script src="http://localhost:81/js/emberjs.js"></script>
    </head>
    <body>
    <script>
    function log(v){
    	console.warn(v)
    }
    var MyApp = {};
    
    //demo1
    MyApp.president = Ember.Object.create({
      name: "Barack Obama"
    });
    
    MyApp.country = Ember.Object.create({
    	//presidentName = Ember.Binding(MyApp.president.name)
      presidentNameBinding: 'MyApp.president.name'
    });
    
    log( MyApp.country.get('presidentName') );
    
    
    
    
    //demo2
    MyApp.president = Ember.Object.create({
      firstName: "Barack",
      lastName: "Obama",
      fullName: function() {
        return this.get('firstName') + ' ' + this.get('lastName');
      // Tell Ember that this computed property depends on firstName
      // and lastName
      }.property('firstName', 'lastName')
    });
    log( MyApp.president.get('fullName') );
    
    
    //demo3
    //新建模型,模型拥有say方法;
    var Person = Ember.Object.extend({
      say: function(thing) {
        alert(thing);
     }
    });
    //实例化Person
    //var person = Person.create();
    //person.say("hello world");
    
    var tom = Person.create({
    	name : "tom",
    	helloWorld : function(){
    		this.say("Hi " + this.get("name"))
    	}
    });
    //tom.helloWorld();
    
    var yehuda = Person.create({
    	name : "qihao",
    	say : function(){
    		var name = this.get("name");
    		console.log( name )
    		//console.log( this._super() )
    		//this._super("hello"+name)
    	}
    });
    //yehuda.say()
    
    var loud = Person.extend({
    	say : function(thing){
    		//this._super有问题,不知道怎么回事;
    		//this._super(thing);
    	}
    })
    loud("nono");
    
    /*
    Person.reopen({
    	say : function(){
    		alert(1)
    	}
    })
    */
    //(new Person).say()
    
    </script>
    <script type="text/x-handlebars">
      The President of the United States is {{MyApp.president.fullName}}
    </script>
    </body>
    </html>
    

      

  • 相关阅读:
    二分查找
    【递归】N位全排列
    深度学习训练平台Polyaxon食谱 | Polyaxon使用笔记
    PAT A1149 Dangerous Goods Packaging [蜜汁模拟+STL]
    PAT A1124 Raffle for Weibo Followers [模拟+STL]
    PAT A1144 The Missing Number [模拟+STL]
    PAT A1120 Friend Numbers [模拟]
    PAT A1100 Mars Numbers [字符串处理+硬核模拟]
    PAT A1095 Cars on Campus [排序+硬核模拟]
    PAT A1113 Integer Set Partition [模拟]
  • 原文地址:https://www.cnblogs.com/diligenceday/p/3659038.html
Copyright © 2020-2023  润新知