Created
          July 2, 2018 06:12 
        
      - 
      
- 
        Save fanjiawei/c72ed21f07053fd6067b73e15ceac64c to your computer and use it in GitHub Desktop. 
    // source http://jsbin.com
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script> | |
| <script src="http://builds.emberjs.com/tags/v1.13.5/ember-template-compiler.js"></script> | |
| <script src="http://builds.emberjs.com/tags/v1.13.5/ember.debug.js"></script> | |
| <script src="http://builds.emberjs.com/tags/v1.13.6/ember-data.js"></script> | |
| <title>PromiseObject的使用</title> | |
| </head> | |
| <body> | |
| <script type="text/x-handlebars"> | |
| <h2>Welcome to Ember.js</h2> | |
| {{outlet}} | |
| </script> | |
| <script type="text/x-handlebars" data-template-name="index"> | |
| <h1>PromiseObject结果</h1> | |
| <ul> | |
| {{#each item in model}} | |
| <li>{{item.name}}</li> | |
| {{/each}} | |
| </ul> | |
| <hr/> | |
| <h1>PromiseArray结果</h1> | |
| <ul> | |
| {{#each item in promiseArray}} | |
| <li>{{item}}</li> | |
| {{/each}} | |
| </ul> | |
| </script> | |
| <script id="jsbin-javascript"> | |
| var customers = [ | |
| {id:'1',name:'张三'}, | |
| {id:'2',name:'李四'}, | |
| {id:'3',name:'王五'} | |
| ] | |
| var App = Ember.Application.create(); | |
| App.Router.map(function () { | |
| // put your routes here | |
| }); | |
| App.IndexRoute = Ember.Route.extend({ | |
| model: function () { | |
| return ['1', '2', '3']; | |
| }, | |
| setupController:function(controller,model){ | |
| controller.set('model',model.map(function(i){ | |
| //PromiseObject的使用方法 | |
| return DS.PromiseObject.create({ | |
| //create的时候设置一个promise属性即可 | |
| promise: new Ember.RSVP.Promise(function(resolve,reject){ | |
| Ember.run.later(this,function(){ | |
| resolve(customers.findBy('id', i)); | |
| }, 1000); | |
| }) | |
| }); | |
| })); | |
| //PromiseArray的使用方法 | |
| controller.set('promiseArray', DS.PromiseArray.create({ | |
| //create的时候设置一个promise属性即可 | |
| promise: new Ember.RSVP.Promise(function(resolve,reject){ | |
| Ember.run.later(this,function(){ | |
| resolve(['one','two','three']); | |
| },2000) | |
| }) | |
| })) | |
| } | |
| }); | |
| </script> | |
| <script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <script src="https://code.jquery.com/jquery-1.11.1.min.js"><\/script> | |
| <script src="//builds.emberjs.com/tags/v1.13.5/ember-template-compiler.js"><\/script> | |
| <script src="//builds.emberjs.com/tags/v1.13.5/ember.debug.js"><\/script> | |
| <script src="//builds.emberjs.com/tags/v1.13.6/ember-data.js"><\/script> | |
| <title>PromiseObject的使用</title> | |
| </head> | |
| <body> | |
| <script type="text/x-handlebars"> | |
| <h2>Welcome to Ember.js</h2> | |
| {{outlet}} | |
| <\/script> | |
| <script type="text/x-handlebars" data-template-name="index"> | |
| <h1>PromiseObject结果</h1> | |
| <ul> | |
| {{#each item in model}} | |
| <li>{{item.name}}</li> | |
| {{/each}} | |
| </ul> | |
| <hr/> | |
| <h1>PromiseArray结果</h1> | |
| <ul> | |
| {{#each item in promiseArray}} | |
| <li>{{item}}</li> | |
| {{/each}} | |
| </ul> | |
| <\/script> | |
| </body> | |
| </html></script> | |
| <script id="jsbin-source-javascript" type="text/javascript">var customers = [ | |
| {id:'1',name:'张三'}, | |
| {id:'2',name:'李四'}, | |
| {id:'3',name:'王五'} | |
| ] | |
| var App = Ember.Application.create(); | |
| App.Router.map(function () { | |
| // put your routes here | |
| }); | |
| App.IndexRoute = Ember.Route.extend({ | |
| model: function () { | |
| return ['1', '2', '3']; | |
| }, | |
| setupController:function(controller,model){ | |
| controller.set('model',model.map(function(i){ | |
| //PromiseObject的使用方法 | |
| return DS.PromiseObject.create({ | |
| //create的时候设置一个promise属性即可 | |
| promise: new Ember.RSVP.Promise(function(resolve,reject){ | |
| Ember.run.later(this,function(){ | |
| resolve(customers.findBy('id', i)); | |
| }, 1000); | |
| }) | |
| }); | |
| })); | |
| //PromiseArray的使用方法 | |
| controller.set('promiseArray', DS.PromiseArray.create({ | |
| //create的时候设置一个promise属性即可 | |
| promise: new Ember.RSVP.Promise(function(resolve,reject){ | |
| Ember.run.later(this,function(){ | |
| resolve(['one','two','three']); | |
| },2000) | |
| }) | |
| })) | |
| } | |
| });</script></body> | |
| </html> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var customers = [ | |
| {id:'1',name:'张三'}, | |
| {id:'2',name:'李四'}, | |
| {id:'3',name:'王五'} | |
| ] | |
| var App = Ember.Application.create(); | |
| App.Router.map(function () { | |
| // put your routes here | |
| }); | |
| App.IndexRoute = Ember.Route.extend({ | |
| model: function () { | |
| return ['1', '2', '3']; | |
| }, | |
| setupController:function(controller,model){ | |
| controller.set('model',model.map(function(i){ | |
| //PromiseObject的使用方法 | |
| return DS.PromiseObject.create({ | |
| //create的时候设置一个promise属性即可 | |
| promise: new Ember.RSVP.Promise(function(resolve,reject){ | |
| Ember.run.later(this,function(){ | |
| resolve(customers.findBy('id', i)); | |
| }, 1000); | |
| }) | |
| }); | |
| })); | |
| //PromiseArray的使用方法 | |
| controller.set('promiseArray', DS.PromiseArray.create({ | |
| //create的时候设置一个promise属性即可 | |
| promise: new Ember.RSVP.Promise(function(resolve,reject){ | |
| Ember.run.later(this,function(){ | |
| resolve(['one','two','three']); | |
| },2000) | |
| }) | |
| })) | |
| } | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment