我有一个javascript函数,我想转换为ember js。对于应用程序(http://www.wilhelminaschool.eu/app2)此函数对特定日期项“mbwpc-start”上的json文件进行排序,仅显示从今天到未来的项目以及未显示的旧项目。
我将它转换为ember js函数吗?
function showAgenda() {
var wpAPI = 'http://www.wilhelminaschool.eu/api/?json=get_recent_posts&include=id,title,custom_fields&count=150&post_type=mbwpc_event';
$.getJSON(wpAPI, function(result) {
// first, you must sort your items by the desired criteria,
// mbwpc-start descending
result.posts.sort(function(left, right) {
return parseInt(right["custom_fields"]["mbwpc-start"]) - parseInt(left["custom_fields"]["mbwpc-start"]);
});
var today = new Date();
//today = today.toDateString(); // "Thu Dec 19 2013"
today = today.getTime(); // "Thu Dec 19 2013"
var itemCount = 0;
$.each(result.posts.reverse(), function(i, item) {
// the date of the calender item
var postDate = new Date(item["custom_fields"]["mbwpc-start"] * 1000);
//if ( postDate.toDateString() == today ) {
if (postDate.getTime() >= today) {
var html = '<li><h3>' + item.title + '</h3><p>' + postDate.getDate() + '-' + (postDate.getMonth() + 1) + '-' + postDate.getFullYear() + '</p></li>';
$("#list").append(html);
// Count, and break the loop if necessary
if (++itemCount >= 10)
return false; // break the loop
}
});
$("#list").listview('refresh');
}); // end getjson
} // end function