underscore.js

underscore.js nested templates

给你一囗甜甜゛ 提交于 2019-12-20 08:28:01
问题 Is it possible to somehow take a DOM element from a underscore template and use it as another template? The idea is that my app needs to render a document that contains a loop with items and a summary. I need to occasionaly re-render only the summary or a few items, so I cannot just re-render the whole document. However, I would like to keep it simple for the app users to create their own templates for the document and I think that keeping everything in one file for a document would make it

Missing Javascript “.map” file for Underscore.js when loading ASP.NET web page [duplicate]

孤者浪人 提交于 2019-12-20 08:05:42
问题 This question already has answers here : jQuery's jquery-1.10.2.min.map is triggering a 404 (Not Found) (11 answers) Closed 5 years ago . I have a web page that is part of a ASP.NET web site running on Azure. It's run fine for quite a while now. Out of the blue, I am suddenly having a problem with the browser trying to download a ".map" for Underscore.js. I did some reading and apparently JQuery creates ".map" files as debugging aids for Javascript source files (".js"). However, if I look at

Flatten a nested array of objects over a array field

女生的网名这么多〃 提交于 2019-12-20 07:13:02
问题 Have an object a1 = [{name:'x',age:21, addr:[{flat:1,add:'xyz'},{flat:2,add:'xsr'}]}, {name:'y',age:22, addr:[{flat:3,add:'xyz1'},{flat:4,add:'xsr1'}]] Desired output: [{name:'x',age:21, addr:{flat:1,add:'xyz'}}, {name:'x',age:21, addr:{flat:2,add:'xsr'}}, {name:'y',age:22, addr:{flat:3,add:'xyz1'}, {name:'y',age:22, addr:{flat:4,add:'xsr1'}] Please suggest! I am trying to accomplish this using lodash/underscore. 回答1: Map every item in the original array to a new array, with a number of items

Backbone.js Underscore.js filtering a collection vs array

筅森魡賤 提交于 2019-12-20 06:38:13
问题 I'm basically trying to do what is done with this question, but with an array and return all objects using the values of the corresponding array, not just the value: Filter backbone collection by attribute value My natural instinct is to use _.filter or _.partition on the persons collection, but am confused on how these are being compared & returned and am not getting the desired outcome. With the following, passing the id in via the router: friendsRoute: function(id){ persons = new App

Passing data to underscore for rendering not working

橙三吉。 提交于 2019-12-20 05:24:13
问题 I am trying to render an underscore template which is the one below div.col-md-12#english select(value="", class="form-control") option | Select Your Language Preference script(type="text/template" id="english-pref") <% if (selected === "US") { %> option(value="US", selected) | United States <% } else %> <% if(selected === "US"){ %> option(value="UK", selected) | United Kingdom <% } %> Here is my Backbone View code app.NotesView = Backbone.View.extend({ el: '#notes', events: { 'click #save':

angularjs counting object length

ε祈祈猫儿з 提交于 2019-12-20 03:53:14
问题 I'm using underscore to count object length. _.size(object) . Because this object is being handled by angularjs there's a $$hashKey property in the object that's making the length 1 larger than it should be. What's the correct way to count object lengths in angularjs? 回答1: Will this do? _.size(_.omit(object, '$$hashKey')); Updated angular.copy() strips $$hashKey out for you. So it seems a more Angular way would be _.size(angular.copy(object)); . 回答2: What about _.size(angularObject) - 1; ? If

How to pass additional variables in to underscores templates

大城市里の小女人 提交于 2019-12-19 21:52:26
问题 I've a backbone view that renders a search result in a underscore template. As I want to highlight the search term in the result I have the following print method in the template: print(someKey.replace(searchTerm, '<b>' + searchTerm + '</b>') It works as aspected, but I have to set the searchTerm variable in the global namespace to get this work. I wonder if there is a way to access my views model in the print method, so I could write it like this: print(someKey.replace(searchTerm, '<b>' +

combine html template files into one JS file

折月煮酒 提交于 2019-12-19 17:46:28
问题 I have HTML template files (underscore template syntax) These files are saved in HTML format so they would be easy to edit (IDE syntax highlight) I don't want to fetch them with ajax, but rather combine them all and include them as a js file. Using GULP as my task-runner, I would like it to somehow combine all the HTML to something like this, as a javascript file that I could include in my BUILD process: template_file_name is the HTML file name. var templates = { template_file_name : '..

How to loop through the alphabet via underscoreJS

会有一股神秘感。 提交于 2019-12-19 05:23:12
问题 I'm using Underscore's template() method in BackboneJS views. I'd like to show a list of alphabet letters in my view in order to sort a collection by letter. As a result, I have a list of 26 links (one link = one letter) in my view. Instead of copy-pasting each link (which is very bad for code maintainability), I was wondering if it was possible to loop through the alphabet via underscoreJS. Result to display : <li ><a href="#">a</a></li> <li ><a href="#">b</a></li> <li ><a href="#">c</a></li

How to pass in package.json array to grunt.js

こ雲淡風輕ζ 提交于 2019-12-19 05:19:18
问题 is there a way to pass in an array to grunt.js from the package.json file? I've tried a few different ways and none of them seem to work. I currently have: /*global module:false*/ module.exports = function(grunt) { // Project configuration. grunt.initConfig({ pkg: '<json:package.json>', lint: { files: '<%= pkg.lint.join(", ") %>' } // Default task 'lint qunit concat min' grunt.registerTask('default', 'lint'); }; package.json { "lint": [ "grunt.js", "test.js" ] } The only solution that I have