Search Results

Search found 7898 results on 316 pages for 'underscore js'.

Page 9/316 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Backbone.js Model change events in nested collections not firing as expected

    - by Pallavi Kaushik
    I'm trying to use backbone.js in my first "real" application and I need some help debugging why certain model change events are not firing as I would expect. I have a web service at /employees/{username}/tasks which returns a JSON array of task objects, with each task object nesting a JSON array of subtask objects. For example, [{ "id":45002, "name":"Open Dining Room", "subtasks":[ {"id":1,"status":"YELLOW","name":"Clean all tables"}, {"id":2,"status":"RED","name":"Clean main floor"}, {"id":3,"status":"RED","name":"Stock condiments"}, {"id":4,"status":"YELLOW","name":"Check / replenish trays"} ] },{ "id":47003, "name":"Open Registers", "subtasks":[ {"id":1,"status":"YELLOW","name":"Turn on all terminals"}, {"id":2,"status":"YELLOW","name":"Balance out cash trays"}, {"id":3,"status":"YELLOW","name":"Check in promo codes"}, {"id":4,"status":"YELLOW","name":"Check register promo placards"} ] }] Another web service allows me to change the status of a specific subtask in a specific task, and looks like this: /tasks/45002/subtasks/1/status/red [aside - I intend to change this to a HTTP Post-based service, but the current implementation is easier for debugging] I have the following classes in my JS app: Subtask Model and Subtask Collection var Subtask = Backbone.Model.extend({}); var SubtaskCollection = Backbone.Collection.extend({ model: Subtask }); Task Model with a nested instance of a Subtask Collection var Task = Backbone.Model.extend({ initialize: function() { // each Task has a reference to a collection of Subtasks this.subtasks = new SubtaskCollection(this.get("subtasks")); // status of each Task is based on the status of its Subtasks this.update_status(); }, ... }); var TaskCollection = Backbone.Collection.extend({ model: Task }); Task View to renders the item and listen for change events to the model var TaskView = Backbone.View.extend({ tagName: "li", template: $("#TaskTemplate").template(), initialize: function() { _.bindAll(this, "on_change", "render"); this.model.bind("change", this.on_change); }, ... on_change: function(e) { alert("task model changed!"); } }); When the app launches, I instantiate a TaskCollection (using the data from the first web service listed above), bind a listener for change events to the TaskCollection, and set up a recurring setTimeout to fetch() the TaskCollection instance. ... TASKS = new TaskCollection(); TASKS.url = ".../employees/" + username + "/tasks" TASKS.fetch({ success: function() { APP.renderViews(); } }); TASKS.bind("change", function() { alert("collection changed!"); APP.renderViews(); }); // Poll every 5 seconds to keep the models up-to-date. setInterval(function() { TASKS.fetch(); }, 5000); ... Everything renders as expected the first time. But at this point, I would expect either (or both) a Collection change event or a Model change event to get fired if I change a subtask's status using my second web service, but this does not happen. Funnily, I did get change events to fire if I added one additional level of nesting, with the web service returning a single object that has the Tasks Collection embedded, for example: "employee":"pkaushik", "tasks":[{"id":45002,"subtasks":[{"id":1..... But this seems klugey... and I'm afraid I haven't architected my app right. I'll include more code if it helps, but this question is already rather verbose. Thoughts?

    Read the article

  • Morris.JS X-Axis Label Height

    - by Aaron
    I have a chart generated with Morris.JS but the labels on the x-axis are to long and being cut off due to the limited height of the area showing the labels. The code below would render a graph that only shows the partial label for "COUNTY PARK ROAD ELEM.". How can I adjust the height of the label area to show the entire text? The code is as follow if ($('#IP1').length){ Morris.Bar({ element: 'IP1', data: [ {x: 'COUNTY PARK ROAD ELEM.', yIndex: 376.92} ], xkey: 'x', ykeys: ['yIndex'], labels: ['Index Points'], ymax: 500, barRatio: 0.2, xLabelAngle: 45, hideHover: 'auto' }); }

    Read the article

  • Raphael JS - Parsing an SVG on the fly

    - by Chris
    I found a neat SVG parser at http://bkp.ee/atirip/ which parses an SVG file and outputs it into javascript that uses the Raphael JS library (raphaeljs.com). You'll notice in the source code at http://bkp.ee/atirip/svg2rdemo.php : <script> jQuery(document).ready( function() { $("#c1").each(function(){ var c = Raphael(this, 190, 154, 0, 0); var g1 = c.set(); ... it creates variables like g1, g2, etc. But it also reuses these variables. I would like to create unique variables for each group. In my .ai file, I have named my groups and I would like to use these names to create the variable names. Where in http://bkp.ee/atirip/f/svgToRaphaelParser.php.zip should I look to make this change?

    Read the article

  • Target iframe Raphael Js

    - by user299343
    Ive been trying to target iframe using Raphael JS heres some sample code var c = paper.circle(10, 10, 10); c.attr({href: "http://google.com/", target: "top"}); v var t = paper.text(250, 50, "Raphaël\nkicks\nbutt!"); t.attr({href: "http://google.com/", target: "_blank"}); Also..cant get href to work with text ar t = paper.text(50, 50, "Raphaël\nkicks\nbutt!"); t.attr({href: "http://google.com/", target: "_blank"});

    Read the article

  • how to dynamically add observer methods to an Ember.js object

    - by Rick Moss
    So i am trying to dynamically add these observer methods to a Ember.js object holderStandoutCheckedChanged: (-> if @get("controller.parent.isLoaded") @get("controller").toggleParentStandout(@get("standoutHolderChecked")) ).observes("standoutHolderChecked") holderPaddingCheckedChanged: (-> if @get("controller.parent.isLoaded") @get("controller").toggleParentPadding(@get("holderPaddingChecked")) ).observes("holderPaddingChecked") holderMarginCheckedChanged: (-> if @get("controller.parent.isLoaded") @get("controller").toggleParentMargin(@get("holderMarginChecked")) ).observes("holderMarginChecked") I have this code so far but the item.methodToCall function is not getting called methodsToDefine = [ {checkerName: "standoutHolderChecked", methodToCall: "toggleParentStandout"}, {checkerName: "holderPaddingChecked", methodToCall: "toggleParentPadding"}, {checkerName: "holderMarginChecked", methodToCall: "toggleParentMargin"} ] add_this = { } for item in methodsToDefine add_this["#{item.checkerName}Changed"] = (-> if @get("controller.parent.isLoaded") @get("controller")[item.methodToCall](@get(item.checkerName)) ).observes(item.checkerName) App.ColumnSetupView.reopen add_this Can anyone tell me what i am doing wrong ? Is there a better way to do this ? Should i be doing this in a mixin ? If so please

    Read the article

  • Raphael js library: problems with animateAlong in IE7

    - by Andrei
    Hi there, I'm having trouble making a simple shape move along a path in IE7 (the only version of IE I tried, actually). The following code works fine in chrome and firefox, but not IE. I couldn't find an obvious reason, has anybody seen something similar? canvas.path(rPath.path).attr("stroke", "blue"); var circle = canvas.circle(rPath.startX, rPath.startY, 5); circle.animateAlong(rPath.path, 3000, true); My rPath variable has the path and the starting point coordinates. Microsoft script debugger points to this line as the one where the code breaks: os.left != (t = x - left + "px") && (os.left = t); (line 2131 inside the uncompressed raphael.js script file, inside Element[proto].setBox = function (params, cx, cy) {...}) Any ideas? Any experience (good or bad) with raphael's animateAlong in IE7? TIA, Andrei

    Read the article

  • How to prevent a javascript/backbone.js cloned model from sharing attributes

    - by user540727
    I'm working with backbone.js models, so I don't know if my question is particular to the way backbone handles cloning or if it applies to javascript in general. Basically, I need to clone a model which has an attribute property assigned an object. The problem is that when I update the parent or clone's attribute, the other model is also updated. Here is a quick example: var A = Backbone.Model.extend({}); var a = new A({'test': {'some': 'crap'}}); var b = a.clone(); a.get('test')['some'] = 'thing'; // I could also use a.set() to set the attribute with the same result console.log(JSON.stringify(a)) console.log(JSON.stringify(b)) which logs the following: {"test":{"some":"thing"}} {"test":{"some":"thing"}} I would prefer to clone a such that b won't be referencing any of its attributes. Any help would be appreciated.

    Read the article

  • Backbone.js not registering Model.hasChanged event

    - by Brian M. Hunt
    Hello, I'm trying to get a View in Backbone.js to save when there's a 'change' event if (and only if) the data has changed. Long story short, I've a 'change' event set on the View that calls this: function changed_event() { log.debug("Before: " + this.model.get('name')) // not 'contrived!' this.model.set({'name': 'contrived!'}); log.debug("After: " + this.model.get('name')) // 'contrived!' if (this.model.hasChanged()) { alert("This is never called."); } } I'd like to know why the model.hasChanged() is false when clearly the model has been changed. I'm not sure what other information is necessary, but if there is more information that may be helpful please comment and I'll elaborate. Thank you for reading.

    Read the article

  • D3.js binding an object to data and appending for each key

    - by frshca
    I'm a D3.js newbie and I'm learning how to play around with data. Let's say I have an object with names as keys, and each key has an array of numbers like this: var userdata = { 'John' : [0, 1, 3, 9, 8, 7], 'Harry': [0, 10, 7, 1, 1, 11], 'Steve': [3, 1, 4, 4, 4, 17], 'Adam' : [4, 77, 2, 13, 11, 13] }; For each user, I would like to append an SVG object and then plot the line with the array of values for that user. So here is my assumption of how that would look based on tutorials, but I know it is incorrect. This is to show my limited knowledge and give better understanding of what I'm doing: First I should create the line var line = d3.svg.line().interpolate('basis'); Then I want to bind the data to my body and append an svg element for each key: d3.select('body') .selectAll('svg') .data(userdata) .enter() .append('svg') .append(line) .x(function(d, i) { return i; }) .y(function(d) { return d[i]; }); So am I close??

    Read the article

  • Multiple .obj Models in THREE.js and detecting clicked objects

    - by ZedBee
    I have been following along this example to load .obj Model using three.js. Since I needed more than one model to load so I tried this loader.addEventListener( 'load', function ( event ) { var object = event.content; object.position.y = - 80; scene.add( object ); }); loader.load( 'obj/model1.obj' ); loader.load( 'obj/model2.obj' ); First: I don't know whether this is the right approach or not since I searched but didn't find any tutorial loading more than one .obj models. Second: I want to be able to click different models on the screen. I tried this which doest not seem to work for me. Any suggestions on this?

    Read the article

  • Getting-started: Setup Database for Node.js

    - by Emile Petrone
    I am new to node.js but am excited to try it out. I am using Express as a web framework, and Jade as a template engine. Both were easy to get setup following this tutorial from Node Camp. However the one problem I am finding is I can't find a simple tutorial for getting a DB set up. I am trying to build a basic chat application (store session and message). Does anyone know of a good tutorial? This other SO post talks about dbs to use- but as this is very different from the Django/MySQL world I've been in, I want to make sure I understand what is going on. Thanks!

    Read the article

  • Using Ruby Hash instead of Rails ActiveRecord in Coffeescript / Morris.JS

    - by Vanessa L'olzorz
    I'm following the Railscast #223 that introduced Morris.JS. I generate a data set called @orders_yearly in my controller and in my view I have the following to try and render the graph: <%= content_tag :div, "", id: "orders_chart", data: {orders: @orders_yearly} %> Calling @orders_yearly.inspect shows it's just a simple hash: {2009=>1000, 2010=>2000, 2011=>4000, 2012=>100000} I'll need to modify the values for xkey and ykeys in coffeescript to work, but I'm not sure how to make it work with my data set: jQuery -> Morris.Line element: 'orders_chart' data: $('#orders_chart').data('orders') xkey: 'purchased_at' # <------------------ replace with what? ykeys: ['price'] # <---------------------- replace with what? labels: ['Price'] Anyone have any ideas? Thanks!

    Read the article

  • Knockout.js nested sortable bindings

    - by user2391998
    I am working with the knockout.js sortable plugin; however, I ran into a problem that I have so far been unable to solve. I have two sortable bindings, one for buckets and another for bucketItems. I am able to reorder bucketItems between buckets and between buckets; however, I am unable to reorder buckets. Would you have any idea why this would be? I am also using nested with bindings, but as far as I can tell, this is not what is causing problems. I would greatly appreciate any insight you have to offer. Thank you so much for your time!

    Read the article

  • Node.js for lua?

    - by Shahbaz
    I've been playing around with node.js (nodejs) for the past few day and it is fantastic. As far as I can tell, lua doesn't have a similar integration of libev and libio which let's one avoid almost any blocking calls and interact with the network and the filesystem in an asynchronous manner. I'm slowly porting my java implementation to nodejs, but I'm shocked that luajit is much faster than v8 JavaScript AND uses far less memory! I imagine writing my server in such an environment (very fast and responsive, very low memory usage, very expressive) will improve my project immensly. Being new to lua, I'm just not sure if such a thing exists. I'll appreciate any pointers. Thanks

    Read the article

  • help understanding the concept of javascript callbacks with node.js, especially in loops

    - by Mr JSON
    hi I am just starting with node.js. I have done a little ajax stuff but nothing too complicated so callbacks are still kind of over my head. I looked at async but all I need is to run a few functions sequentially. I basically have something that pulls some json from an api, creates a new one and then does something with that. obviously i can't just run it because it runs everything at once and has an empty json. mostly they have to go sequentially but if while pulling a json from the api it can pull other json while it's waiting that is fine. I just got confused when putting the callback in a loop. what do I do with the index? i think i have seen some places that use callback inside the loop as kind of a recusive function and don't use for loops at all. simple examples would help alot thanks!

    Read the article

  • determine if a restaurant is open now (like yelp does) using database, php, js

    - by vee
    i was wondering if anyone knows how yelp determines what restaurants are "open now"? i'm developing a similar application using html/javascript/php. i was going to have a column in my database for each day, with comma separated hours written in "2243" format (10:43 pm). so for example if a restaurant is open for lunch and dinner it might be "1100,1400,1700,2200". then i'd check (using js) if the current time falls in one of the ranges for the current day. i'd also like to be able to determine if a restaurant is "open tonight", "open late", etc. for those i guess i'd check whether the open range overlaps with certain ranges. is there a better way to do this? particularly, how to store the hours in the database and then determine if they overlap with a given set of hours. thanks.

    Read the article

  • node.js with SQL Server Native Client 11 scope_identity not being returned

    - by binderbound
    I'm having trouble with inserting a value into a database through node.js. Here is the offending code: sql.query(conn_str ,"INSERT INTO Login(email, hash, salt, firstName, lastName) VALUES(?, ?, ?, ?, ?); SELECT SCOPE_IDENTITY() AS 'Identity';" , [email, hash, salt, firstName, lastName], function(err, results){ console.log(results) } Unfortunately, the console is just echoing [], meaning results is an empty array, I suppose. Does anyone know why the identity is not being returned? Even if it was null, why isn't results then [{Identity: null }] ? Database is on Azure, which does have a "Scope_Identity" function, and the native client also recognises this function. Using node package "msnodesql" Please Help

    Read the article

  • Count the number of rows of a CSV file, with d3.js

    - by user2934073
    Suppose I have this CSV file Day,What 2013-10-27,Apple 2013-10-27,Cake 2013-10-27,Apple 2013-10-28,Apple 2013-10-28,Apple 2013-10-28,Blueberry 2013-10-28,Orange I would like to drawn with D3.js a time-series graph. All I need to do is to display the sum of the number of rows for each day. As an example, the 27 of November should have 3 as value, the 28th should have 4. Is there a way I can archive it? I've been trying to create a new dataset out of the CSV one with no positive results. var dataset; d3.csv("data.csv", function(d) { return { Day: new Date(d.Day), What: d.What }; }, function(error, rows) { dataset = rows; // I SUPPOSE THE FUNCTION THAT GENERATE THE NEW DATASET SHOULD GO THERE });

    Read the article

  • JS / JQuery character problem

    - by Jimmy Farax
    I have a code which has a character that JS is not handling properly. $(document).ready(function(){ $.getJSON("http://sjama.tumblr.com/api/read/json?callback=?", function (data){ for (var i=0; i<data.posts.length; i++){ var blog = data.posts[i]; var id = blog.id; var type = blog.type; var photo = blog.photo-url-250; if (type == "photo"){ $("#blog_holder").append('<div class="blog_item_holder"><div class="blog_item_top"><img src='+photo+'/></div><div class="blog_item_bottom">caption will go here</div></div>'); } } }); <!-- end $.getJSON }); The problem is with this line: var photo = blog.photo-url-250; after "blog." it reads the "url" part weirdly because of the dash (-) in between. What can I do to sort this problem out?

    Read the article

  • call value inside a JS variable as a JS function name

    - by user1640668
    Hello I have a function to perform actions but name of the function is inside a variable... below code will get the URL's hashed part example: #JHON and remove # and store it inside URLHASH variable..example: JHON var urlhash = document.location.hash; urlhash = urlhash.replace(/^.*#/, ''); always there is a function name from that value inside variable and i want to call value inside that variable as a function name window.onload=function() { Value inside URLHASH variable should run as a name of a variable. example: jhon(); }; Is it possible ? I tried some codes but it calls variable name as a function not value inside the variable..help me..

    Read the article

  • Node.JS Server Cuts Off Frequently?

    - by aherrick
    I have a Node JS Server where I am using Socket.IO to stream content to the browser. It works great for about 45 minutes or so of streaming, then it will usually cut out. There are no "errors" reported in the terminal and the Node server acts like it is in, however the page I am serving clearly stops working. What are my options for trying to get to the bottom of this? Could this be a configuration issue with Node/Socket.IO? is there any basic error logging you would recommend I setup?

    Read the article

  • Backbone.js - Getting JSON back from url

    - by Brian
    While trying to learn Backbone.js, I've been trying to grab the content of a JSON file using the following code: (function($){ var MyModel = Backbone.Model.extend(); var MyCollection = Backbone.Collection.extend({ model : MyModel, url: '/backbone/data.json', parse: function(response) { console.log(response); return response; } }); var stuff = new MyCollection; console.log(stuff.fetch()); console.log(stuff.toJSON()); })(jQuery) 'stuff.fetch()' returns the entire object (with the data I'm after in responseText), 'stuff.toJSON' returns nothing ([]), but the console in the parse method is returning exactly what I want (the json object of my data). I feel like I'm missing something obvious here, but I just can't seem to figure it out why I can't get the right data out. Could someone point me in the right direction or show me what I'm doing wrong here? Am I using a model for the wrong thing?

    Read the article

  • What does addListener do in node.js?

    - by Jeffrey
    I am trying to understand the purpose of addListener in node.js. Can someone explain please? Thanks! A simple example would be: var tcp = require('tcp'); var server = tcp.createServer(function (socket) { socket.setEncoding("utf8"); socket.addListener("connect", function () { socket.write("hello\r\n"); }); socket.addListener("data", function (data) { socket.write(data); }); socket.addListener("end", function () { socket.write("goodbye\r\n"); socket.end(); }); }); server.listen(7000, "localhost");

    Read the article

  • Backbone.js routing without changing url

    - by louism
    I am migrating a single-page web application based on Backbone.js and jQuery to a Chrome extension. However, neither the pushState nor the hashbang-based router modes seem to play well with the environment within the extension. I've come to the conclusion that I'm better off just directly rendering views on user interactions, bypassing the window.location system altogether. However, I'm not too sure how to implement this without changing calls to Router.navigate in dozens of files. Is there a pluggable/modular way to keep the Backbone routing system but bypass any changes to the url?

    Read the article

  • Backbone.js "model" query

    - by Novice coder
    I'm a learning coder trying to understand this code from a sample MVC framework. The below code is from a "model" file. I've done research on Backbone.js, but I'm still confused as to exactly how this code pull information from the app's database. For example, how are base_url, Model.prototype, and Collection.prototype being used to retrieve information from the backend? Any help would be greatly appreciated. exports.definition = { config : { "defaults": { "title": "-", "description": "-" }, "adapter": { "type": "rest", "collection_name": "schools", "base_url" : "/schools/", } }, extendModel: function(Model) { _.extend(Model.prototype, { // Extend, override or implement Backbone.Model urlRoot: '/school/', name:'school', parse: function(response, options) { response.id = response._id; return response; }, }); return Model; }, extendCollection: function(Collection) { _.extend(Collection.prototype, { // Extend, override or implement Backbone.Collection urlRoot: '/schools/', name: 'schools', }); return Collection; } }

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >