ember.js - how to sort embedded records in ember without using ArrayController -
i want sort embedded records in content. had separated embedded record arraycontroller , did sorting on - pretty straight forward, told should use embedded records without arraycontroller. followed http://www.javascriptkit.com/javatutors/arraysort2.shtml sort array objects , content getting sorted view not getting updated accordingly. function looks :
setsort: function (sort) { var sortedcontent = this.get('content.analyticsrunparameters'); sortedcontent.sort(function(a, b){ var cola=a.get(sort).tolowercase(), colb=b.get(sort).tolowercase(); if (cola < colb) //sort string ascending return -1; if (cola > colb) return 1; return 0; //default return value (no sorting) }); this.set('content.analyticsrunparameters',sortedcontent); console.log(sortedcontent);//is sorted console.log(this.get('content.analyticsrunparameters'));//is sorted }
is there way update view when content sorted? or using arraycontroller way around? thanks.
i found solution in post here : ember.arrayproxy changes not triggering handlebars #each update
i don't know if best solution either. seems should able sort array objects without of array proxy. had make minor modification in transform using return arrayproxy instead of normal array of objects :
as.analyticsrunparametertransform = ds.transform.extend({ //return array of ember objects deserialize: function (serialized) { var objects = []; (var key in serialized) { objects.push(ember.object.create({ "name": serialized[key].name, "description": serialized[key].description, "default": serialized[key]["default"], "value": serialized[key].value, "category": serialized[key].category })); } //return objects; return ember.arrayproxy.create({ content: objects }); }, //return json object serialize: function (deserialized) { var analyticstemplate = {}, object; (var = 0, len = deserialized.length; < len; i++) { object = deserialized[i]; analyticstemplate[object.get('name')] = {"name": object.get('name'), "description": object.get('description'), "default": object.get('default'), "value": object.get('value'), "category": object.get('category')}; } return analyticstemplate; } });
Comments
Post a Comment