How to represent arrays within ember-data models?

Well… It was a little bit difficult but mixing all answers in this post I made it work. Firstly, you should create a transform for the new type “array”: DS.ArrayTransform = DS.Transform.extend({ deserialize: function(serialized) { return (Ember.typeOf(serialized) == “array”) ? serialized : []; }, serialize: function(deserialized) { var type = Ember.typeOf(deserialized); if (type == ‘array’) … Read more

camelCase to kebab-case

I have a one-liner similar to Marc’s but with a simpler Regular Expression and ~20% faster according my benchmark (Chrome 89). const kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? “-” : “”) + $.toLowerCase()) const words = [‘StackOverflow’, ‘camelCase’, ‘alllowercase’, ‘ALLCAPITALLETTERS’, ‘CustomXMLParser’, ‘APIFinder’, ‘JSONResponseData’, ‘Person20Address’, ‘UserAPI20Endpoint’]; console.log(words.map(kebabize)); [A-Z]+(?![a-z]) matches any consecutive capital … Read more

Jquery datatables destroy/re-create

CAUSE When DataTables destroys the table because of the option destroy:true it restores original content and discards the content that you’ve generated. SOLUTION #1 Remove destroy:true option and destroy the table before you manipulate the table with destroy() API method. if ( $.fn.DataTable.isDataTable(‘#tblRemittanceList’) ) { $(‘#tblRemittanceList’).DataTable().destroy(); } $(‘#tblRemittanceList tbody’).empty(); // … skipped … $(‘#tblRemittanceList’).dataTable({ “autoWidth”:false, … Read more

Tail Call Optimization implementation in Javascript Engines [duplicate]

TCO, or rather, Tail Call Elimination in JavaScript — also often referred to as Proper Tail Calls (PTC) in discussions — is a long and sad story. Around 2011, TC39 (the JavaScript standards committee) decided to adopt mandatory TCE for the forthcoming ES6 standard, with consensus from all major browser vendors. In 2015, the new … Read more

how to set active class to nav menu from twitter bootstrap

You can use this JavaScript\jQuery code: // Sets active link in Bootstrap menu // Add this code in a central place used\shared by all pages // like your _Layout.cshtml in ASP.NET MVC for example $(‘a[href=”‘ + this.location.pathname + ‘”]’).parents(‘li,ul’).addClass(‘active’); It’ll set the <a>‘s parent <li> and the <li>‘s parent <ul> as active. A simple solution … Read more

Array to Comma separated string and for last tag use the ‘and’ instead of comma in jquery

You can use .slice(): > var a = [1, 2, 3, 4, 5]; > [a.slice(0, -1).join(‘, ‘), a.slice(-1)[0]].join(a.length < 2 ? ” : ‘ and ‘); ‘1, 2, 3, 4 and 5’ a.slice(0, -1).join(‘, ‘): takes all but the last element and joins them together with a comma. a.slice(-1)[0]: it’s the last element. .join(a.length < … Read more

error code: 521