underscore.js

Ignoring undefined data / vars in an underscore template

隐身守侯 提交于 2019-12-23 06:51:35
问题 Still learning backbone so bear with me; I'm trying to add a new model with blank fields to a view, but the template I've created has a whole bunch of <input value="<%= some_value %>" type="whatever" /> Works perfectly fine when fetching data, it populates it and all goes well. The trouble arises when I want to create a new (blank) rendered view, it gives me Uncaught ReferenceError: some_value is not defined I can set defaults (I do already for a few that have default values in the db) but

Menu Button display with main and sub categories using backbone.js

天涯浪子 提交于 2019-12-23 04:55:10
问题 I have a menu button where i have render main categories and on mouse over need to render its subcategories.Now i am able to render the main categories but not subcategories. This is my View. var Product_View = Backbone.View.extend({ tagName: 'div', className: 'products', initialize: function (options) { this.options = options || {}; }, events: { "mouseover #category_menu" : "test" }, test: function(){ alert('here...'); //need to add code to render the sub categories here }, render: function(

Backbone.js Pushstate Routing and PHP Framework's Router

↘锁芯ラ 提交于 2019-12-23 04:54:19
问题 I am using Backbone.js along with a PHP MVC framework (Codeigniter, Laravel). I'm confused about how URLs will be handled by the PHP router and Backbone router when using Pushstates. (I have not started using pushstates yet, still using hashbangs # ). I am not working on a single-page-application, but rather the site is made up of several pages that act like single-page-application on its own. Problem: If I have a page http://domain.com/user/user123 , and clicking a link http://domain.com

Grouping a nested array with underscore.js

十年热恋 提交于 2019-12-23 04:47:04
问题 sorry if this seems like a duplicate, but I've tried other answers and I can't seem to get something that works properly. I'm building an AngularJS SPA, and I have data in the following format: "folders": [ { "id": 1, "password": "WPAUGOR452", "year": 2013 }, { "id": 2, "password": "WPAUGOR452", "year": 2013 }, { "id": 3, "password": "DFGOERJ305", "year": 2014 } and many many more. I want folders to be grouped so that it's like this: "folders": [ "2013": [ "WPAUGOR452": [ { "id": 1, "password

How to fetch data from Backbone collection to Template

走远了吗. 提交于 2019-12-23 04:08:15
问题 i am just writing a simple backbone program. But i am not getting how to fetch data from backbone collection to backbone template. Complete code is written below: <!doctype html> <html> <head> <title>Backbone tutorial</title> </head> <body> <div class="user">user</div> <div class="page"></div> <script type="text/template" id="user-list-template"> I am not able to get data on daya.key <h1> <%= data.key %> </h1> </script> <script type="text/javascript" src="jquery.js"></script> <script type=

How to remove array objects having property

会有一股神秘感。 提交于 2019-12-23 04:04:15
问题 What is the easiest way to remove all objects from an array with a particular property = x? 回答1: Use _.filter var result = _.filter(arr, function(item) { return !("prop" in item); }); If you want to limit it to the immediate properties of each item, use var result = _.filter(arr, function(item) { return !item.hasOwnProperty("prop"); }); 回答2: It seems like the easiest way would be to use the filter method: var newArray = _.filter(oldArray, function(x) { return !('prop' in x); }); // or var

How to remove array objects having property

时间秒杀一切 提交于 2019-12-23 04:04:11
问题 What is the easiest way to remove all objects from an array with a particular property = x? 回答1: Use _.filter var result = _.filter(arr, function(item) { return !("prop" in item); }); If you want to limit it to the immediate properties of each item, use var result = _.filter(arr, function(item) { return !item.hasOwnProperty("prop"); }); 回答2: It seems like the easiest way would be to use the filter method: var newArray = _.filter(oldArray, function(x) { return !('prop' in x); }); // or var

Different styling on the third record in Backbone + Marionette + Rails

浪子不回头ぞ 提交于 2019-12-23 03:58:14
问题 I've decided to step into the Backbone arena & after searching through BB's & Marionette's doc, I'm having a little trouble with something seemingly simple. I'm simply trying to customize what's being display on the third record. Here's how I would do it just using Rails <% @posts.each_with_index do |post, i| %> <% if i == 1 || i == 7 || i == 14 %><!-- 1st, 7th, & 14th record --> display title, description & something else <% else %><!-- other records --> display only title <% end %> <% end %

Pass exisiting Object from Parse Class otherwise create a new object

我们两清 提交于 2019-12-23 03:00:45
问题 As of right now I have a beforeSave function that prevents duplicate emails from being saved shown below. Parse.Cloud.beforeSave("Email", function(request, response) { var query = new Parse.Query("Email"); // Gets the email key value (string) before object is saved query.equalTo("address", request.object.get("address")); // Checks to see if an object for that email already exists query.first({ success: function(object) { if (object) { response.error("Email already Exists"); } else { response

Converting Json object in to array

时光毁灭记忆、已成空白 提交于 2019-12-23 02:55:17
问题 From the below Json, I am trying to build an array as shown 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" } ] } ] Desired Array: { "Display Name": 'Rya', "UserName" : "RH", value: 350 }, { "Display Name": 'Mike'