First, my current versions:
Ember : 2.8.1
Ember Data : 2.8.1
jQuery : 3.1.1
I'm using query params in a controller. If a user goes to assignments?strm=1292
, the strm
, computed term,
and computed filteredClusters
will be called. However, the filteredClusters
will be empty on the initial page load (e.g. I navigate to /assignments?strm=1292
using my browser). It is only after the selectStrm
action is called to update the strm
query param that filteredClusters
will start returning results.
My assignments
index controller is listed below:
import Ember from 'ember';
export default Ember.Controller.extend({
queryParams: ['strm', 'cluster', 'title'],
strm: null,
cluster: null,
title: null,
term: Ember.computed('strm', function() {
var strm = this.get('strm');
var terms = this.get('model.terms');
return strm ? terms.filterBy('strm', strm)[0] : null;
}),
filteredClusters: Ember.computed('term', 'model', function() {
var term = this.get('term');
var clusters = this.get('model.clusters');
if(term) {
return clusters.filter( (cluster, index, clusters) => {
var terms = cluster.get('terms');
return terms.mapBy('strm').includes(term.get('strm'));
});
} else {
return clusters;
}
}),
actions: {
selectStrm: function(strms) {
var strm = strms[0];
this.set('strm', strm);
}
}
});
What can I do to get filteredClusters
loaded on the initial page load?
Thank you for any and all information.
Aucun commentaire:
Enregistrer un commentaire