underscore.js

Underscore.js to filter out the unique values

梦想与她 提交于 2019-12-12 09:39:48
问题 Here is a link to my Fiddle I have a table that is created dynamically from the JSON obtained from a Ajax response. I have duplicate entries in the table. For example xxx,xxx . I want to group them and have it like <td data-count="some count">xxx</td> I tried using underscore.js but it seems to break the rowspan functionality. I converted the arr into a object using _countBy(arr) and I obtained an object of the following format. {xxx: 2, zzz: 1} Question : How can I modify the generateTable()

jQuery get raw text (unescaped) for further parsing via underscore templates

拟墨画扇 提交于 2019-12-12 08:53:36
问题 I currently have an html modal block like so: <div id="modal"> <div class="header_buttons"></div> <p> Are you sure you would like to perform <%= action_name %> on <%= count %> objects? </p> <div class="footer_buttons"> <button>Do <%= action_name %></button> </div> </div> I'd like to parse this content through _.template $("#modal").html() //-> escapes `<%` $("#modal").text() //-> doesn't escape, but doesn't include tags. My immediate solution is to target each element instead of the whole

underscore.js: _.throttle(function, wait)

大兔子大兔子 提交于 2019-12-12 08:23:23
问题 According the underscore documentation: throttle_.throttle(function, wait) Creates and returns a new, throttled version of the passed function, that, when invoked repeatedly, will only actually call the original function at most once per every wait milliseconds. Useful for rate-limiting events that occur faster than you can keep up with. What does it means Useful for rate-limiting events that occur faster than you can keep up with . This function is equivalent to setTimeout with a function

Is it possible to get the index you're sorting over in Underscore.js?

▼魔方 西西 提交于 2019-12-12 07:32:12
问题 I'm using the JS library Underscore and in particular using the _.each and _.sortby library calls. I'm wondering if there's any possible way to get the index of the value within the iterator delegate _.sortBy([1, 4, 2, 66, 444, 9], function(num){ /*It'd be great to have access to the index in here */ return Math.sin(num); }); 回答1: Index is actually available like; _.sortBy([1, 4, 2, 66, 444, 9], function(num, index){ }); 回答2: You can get the index of the current iteration by adding another

How to use underscore.js to produce a flatten result

☆樱花仙子☆ 提交于 2019-12-12 07:13:20
问题 The json object is var data = [{"Parent":1,"Child":[4,5,6]},{"Parent":2},{"Parent":3}] How can I use underscore.js chain/map/pluck etc... function to get the flatten result var result = []; for (var i = 0; i < data.length; i++) { result.push(data[i].Parent); if (data.Child != undefined) { for (var j = 0; j < data[i].Child.length; j++) { result.push(data[i].Child[j]); } } } console.log(result) >> //1,4,5,6,2,3 回答1: Here's a shorter solution: flat = _.flatten(_.map(data, _.values)) 回答2:

Displaying ajax results from yahoo finance using underscore.js

为君一笑 提交于 2019-12-12 05:18:48
问题 Script is successfully retrieving data but I can not get the results of the "row" to display using underscore.js. The specific point of failure is the "var = resultContentTemplate". Can not figure this out. $(document).ready(function(){ var symbols = symbols || ['GOOG','A','AA','AAN']; var yqlUrl = "http://query.yahooapis.com/v1/public/yql"; var historicalUrl = 'http://finance.yahoo.com/d/quotes.csv'; var queryTemplate = _.template("select * from csv where url='" + historicalUrl + "?s=<%=

Is this return statement in the _.delay function of underscore.js extraneous?

可紊 提交于 2019-12-12 04:19:06
问题 This is the code for _.delay : // Delays a function for the given number of milliseconds, and then calls // it with the arguments supplied. _.delay = function(func, wait) { var args = slice.call(arguments, 2); return setTimeout(function() { return func.apply(null, args); }, wait); }; The first return statement before setTimeout is definitely useful because it returns the timeoutID that can be used to cancel the timer. No question there. However, I do not see how the return statement within

Combine multiple arrays by same key [duplicate]

主宰稳场 提交于 2019-12-12 03:55:03
问题 This question already has answers here : Combining JavaScript objects in an array with same key value (4 answers) Closed 2 years ago . I'm trying combine multiple arrays by a specific key property. For example, I have arr1 [{ key: 'A', items: [{name: 'a item'}] }, { key: 'B', items: [{name: 'b item'}] }] arr2 [{ key: 'B', items: [{name: 'another b item'}, {name: 'more b items'}, {name: 'even more b items'}] }] How do I produce the following arr3 ? [{ key: 'A', items: [{name: 'a item'}] }, {

_.mapObject is not supported in meteor

偶尔善良 提交于 2019-12-12 03:52:20
问题 _.mapObject is not supported in meteor. How to use _.mixin to work _.mapObject . Please refer to my code below var result = _.mapObject(typesOverall, function(val, key) { return _.reduce(val, function(memo, v) { return memo + v.val; }, 0) / val.length * 10; }) 来源: https://stackoverflow.com/questions/39153000/mapobject-is-not-supported-in-meteor

Highcharts series data not working

ぃ、小莉子 提交于 2019-12-12 03:38:56
问题 My existing array is as below: "Issues": [{ "Id": null, "Key": null, "Values": [{ "Key": "Display Name", "Value": "Rya" }, { "Key": "UserName", "Value": "RH" }, { "Key": "Count", "Value": "350" }] }, { "Id": null, "Key": null, "Values": [{ "Key": "Display Name", "Value": "Mike" }, { "Key": "UserName", "Value": "ML" }, { "Key": "Count", "Value": "90" }] }] My desired array: [{ name: 'Rya', value: 350 }, { name: 'Mike', value: 90 }] What I tried: Data.Issues.map(o=> o.Values.reduce((acc, {Key,