[英]Ember.js - how to filter a model?
我正在嘗試找出如何最好的方法來創建一種使用Ember.js基於屬性提取特定對象的方法。
現在,我的模型如下所示:
App.Resume = Ember.Object.extend()
App.Resume.reopenClass
store: {}
findAll: ->
arr = Ember.ArrayProxy.create()
if xhr
xhr.abort()
return
xhr = $.ajax(
url: '../json/cv.json'
dataType: 'json'
timeout: 10000
).done (response) =>
response.users.forEach (user, i) =>
cv = @findOne(user.personId)
cv.setProperties(user)
return
values = (values for keys, values of @store)
arr.set('content', values)
arr
findOne: (id) ->
cv = @store[id]
if not cv
cv = App.Resume.create
id: id
@store[id] = cv
cv
如果查看完成的回調中的循環,您會看到它正在使用user.id創建模型-還有一個user.specialization字段。 我希望能夠過濾的是該領域。
任何想法/幫助將不勝感激!
謝謝!
豐富
您可以在任何Ember Enumerable
上使用filterProperty
,例如Array
或ArrayProxy
。 默認情況下,它與存在狀態匹配。 您還可以傳入一個參數以匹配數組中的每個屬性。 您可以將其與計算屬性配對以在視圖中進行綁定。
filtered: function() {
return this.get('products').filterProperty('outOfStock')
}.property('products')
有關示例,請參見此jsbin 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.