emberJS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | <! 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 > |
天道酬勤
本文作者:方方和圆圆
本文链接:https://www.cnblogs.com/diligenceday/p/3659038.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步