2013-06-29 3 views
2

Ember.js를 사용하여 특성을 기반으로 특정 개체를 가져 오는 메서드를 만드는 가장 좋은 방법을 찾는 방법을 찾으려고합니다. 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 필드도 있습니다. 내가 필터링 할 수있는 필드입니다.

모든 아이디어/도움을 주시면 감사하겠습니다.

감사합니다.

리치

답변

4

당신은 Array 또는 ArrayProxy 원하는 엠버 EnumerablefilterProperty를 사용할 수 있습니다. 기본적으로 현재 상태와 일치합니다. 인수를 전달하여 배열의 각 속성과 일치시킬 수도 있습니다. 보기에서 바인드 할 계산 된 특성과이를 쌍으로 연결할 수 있습니다.

filtered: function() { 
    return this.get('products').filterProperty('outOfStock') 
}.property('products') 

예제를 보려면 jsbin을 참조하십시오.

관련 문제