// JavaScript

Array of Hash Dynamic Search

To reorder the array by subcategory within the array, the following structure can be used.

 

//data.categories array'ının içerisinde order adında bir alt alan var buna göre sıralama yenileniyor.
data.categories.sort(dynamicSort("order"));

//Dinamik sıralama yapan fonsiyon
function dynamicSort(property) {
    var sortOrder = 1;
    if(property[0] === "-") {
        sortOrder = -1;
        property = property.substr(1);
    }
    return function (a,b) {
        /* next line works with strings and numbers, 
         * and you may want to customize it to your needs
         */
        var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
        return result * sortOrder;
    }
}


//yukarıdaki işlemlerin anlanmı olabilmesi için aşağıda bilgi amaçlı kod yapısı gösterilmektedir.
//categoryDetails nesnesine integer olarak order alanı ekleniyor
categoryDetails.order = parseInt(cats.getDisplayValue("value"));
//categories nesnesine categoryDetails nesnesi ekleniyor.
data.categories.push(categoryDetails);

 

// JOIN THE CONVERSATION

Share your experience

Bir sorunun, farklı bir çözümün veya eklemek istediğin bir notun var mı? Giriş yapmadan da yazabilirsin.

// KEEP READING

One more note.

All posts ↗︎