2015-01-12 3 views
0

내가 원하는 것은 쿠키가 설정되었는지 여부에 따라 기본값을 기본값으로 설정하는 것입니다. App.Route의 afterModel에서이 검사를 수행하고 있습니다.Ember.sets가 App.Route의 afterModel에서 호출 될 때 Ember.js classNameBindings가 실행되지 않습니다.

쿠키가 설정된 경우 쿠키 값을 기간 배열의 첫 번째 멤버로 설정하지 않으면 쿠키 값을 사용하십시오.

클래스 이름은 Duration Button 구성 요소에 바인딩되어 있으며 초기 값을 선택한 후에 예상대로 작동합니다.

나는 Ember에게 새로운 것이고 나는 이것이 잘못된 길로 가고 있는지, 아니면 내가 놓친 것을 궁금해하니? 당신이 관찰/속성을 설정하려면

App.Route = Ember.Route.extend({ 
    model: function() { 
    return Ember.RSVP.hash({ 
     categories: categories, 
     durations: durations 
    }) 
    }, 
    actions: { 
    setDuration: function(duration) { 
     var idx = durations.indexByPropertyValue('selected',true); 
     if (idx >= 0) { 
     Ember.set(durations[idx],'selected',false); 
     } 
     idx = durations.indexByPropertyValue('seconds',duration); 
     if (idx >= 0) { 
     Ember.set(durations[idx],'selected',true); 
     $.cookie('duration', duration) 
     } 
    } 
    }, 
    afterModel: function(posts, transition) { 
    var duration = $.cookie('duration'); 
    if (duration) { 
     var idx = durations.indexByPropertyValue('seconds', duration); 
     if (idx >= 0) { 
     Ember.set(durations[idx],'selected',true); 
     } 
    } else { 
     duration = durations[0].seconds; 
     Ember.set(durations[0],'selected',true); 
     $.cookie('duration', duration) 
    } 
    } 
}); 

App.DurationButtonComponent = Ember.Component.extend({ 
    classNames: ['btn btn-default'], 
    classNameBindings: ['selected:active'], 
    selectedBinding: "duration.selected", 
    tagName: 'button', 
    click:function(){ 
    if (this.duration.selected) return; 
    this.sendAction('action', this.duration.seconds); 
    } 
}); 


var durations = [ 
    { 
    id: '1', 
    num: '15', 
    unit:'sec', 
    seconds: 15, 
    selected: false 
    }, 
    ... 
    { 
    id: '5', 
    num: '5', 
    unit:'min', 
    seconds: 300, 
    selected: false 
    } 
] 

답변

0

당신은 ember object 할 시간이 필요합니다.

App.Route = Ember.Route.extend({ 
    model: function() { 
    return Ember.RSVP.hash({ 
     categories: categories, 
     durations: [ 
     Ember.Object.create({ 
      id: '1', 
      num: '15', 
      unit:'sec', 
      seconds: 15, 
      selected: false 
     }), 
     Ember.Object.create({ 
      id: '5', 
      num: '5', 
      unit:'min', 
      seconds: 300, 
      selected: false 
     }), 
     ] 

    }) 
    } 
}); 
관련 문제