简体   繁体   English

无法从模板中的Ember.js数据显示记录

[英]Can't Display Records from Ember.js Data in Template

I want to show records from the Ember.js data store in the my template. 我想在我的模板中显示Ember.js数据存储中的记录。 In my controller I have the following code: 在我的控制器中,我有以下代码:

orders: null,

[...] [...]

openOrderModal: function(name) {
  $('.ui.' + name + '.modal').modal('show');
  var orders = this.get('store').peekAll('orders');
  console.log(orders);
  this.set('orders', orders);
},

I peek all records from the data store and save it to a variable. 我查看了数据存储中的所有记录,并将其保存到变量中。 In the template i have a loop. 在模板中,我有一个循环。 But it doesn't work. 但这是行不通的。

{{#each orders as |order|}}
  {{order.id}} {{order.supply_id}}
{{/each}}

Can you help me? 你能帮助我吗?

Kind regards 亲切的问候

peekAll only returns records that are already in the store. peekAll仅返回存储中已存在的记录。 If you did not load any orders elsewhere (like in your route, where records should be loaded) it will return an empty list. 如果您没有在其他地方加载任何订单(例如,在路线中应加载记录的位置),它将返回一个空列表。 It should include unsaved, just created records of the appropriate model, however. 但是,它应包括未保存的,刚刚创建的适当模型的记录

findAll is the method to make the store make API calls, but returns a promise, ie you have to deal with the retrieved records in the then method (unless you load them in your route's model hook, returned promises will be dealt with appropriately). findAll是使商店进行API调用的方法,但是返回一个promise,即您必须在then方法中处理检索到的记录(除非您将它们加载到路线的model挂钩中,否则将适当地处理返回的promise)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM