3.3.4 Lo-Dash


Lo-Dash is a Javascript tool or library that we have made available with the app.js file. This means that like our developers, you have access to it on our templates and can develop with SmartWeb.

Lo-Dash cab be accessed via the _ (underscore) variable, contains brief but incredibly powerful tools for the manipulation of objects, arrays and collections, but can also be used with a micro templating language that can be used to build elements on a website via Javascript. On top of all the examples here, you can find more documentation about Lo-Dash on their website and in their documentation.

Below you will find some short examples of how you can use Lo-Dash:

*CODE* *SNIPPIT**_.pluck function (function () {   var characters = [    { 'name': 'barney', 'age': 36 },    { 'name': 'fred',  'age': 40 }   ];   _.pluck(characters, 'name');   // → ['barney', 'fred'] })();*CODE*

_.map function

*CODE* *SNIPPIT*(function () {   _.map([1, 2, 3], function(num) { return num * 3; });   // → [3, 6, 9]   _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; });   // → [3, 6, 9] (property order is not guaranteed across environments)   var characters = [    { 'name': 'barney', 'age': 36 },    { 'name': 'fred',  'age': 40 }   ];   // using "_.pluck" callback shorthand   _.map(characters, 'name');   // → ['barney', 'fred'] })();*CODE*

_.template function

*CODE* *SNIPPIT*(function () {   var compiled = _.template('hello <%= name %>');   compiled({ 'name': 'fred' });   // → 'hello fred'   _.template('hello <%= name %>', { 'name': 'world' });   // → 'hello world!' })();*CODE*

_.random function

*CODE* *SNIPPIT*(function () {   _.random(0, 100);   // → Random integer between 0 and 100 })();*CODE*

_.range function

*CODE* *SNIPPIT*(function () {   _.range(4);   // → [0, 1, 2, 3] })();*CODE*