|
Hey. I have an XML request which gives me a list of data. An older version of these data already exist on the webpage. Both data are variants on a simple list. What's the best way of syncing these lists? In the HTML list, each item is in its own div, and the XML nodes from the new list are being looped through. The method I can think of at the moment, is to remove all old (HTML) items from the new (XML) list. If an item isn't found in the XML list, it's removed from the HTML. At the end, all the remaining items in the XML are added to the HTML div list. This poses data structure problems, and I'm not familiar with how best to handle lists in javascript. Would arrays be the way forward?
|
# ¿ Jun 12, 2009 21:16 |
|
|
# ¿ May 6, 2024 03:06 |
|
Supervillin posted:Performance-wise it seems like it would be much faster to just replace the whole list than to sync using two or possibly three loops through each set. Maybe I'm too tired or something, but wouldn't you get the same data if you destroy the HTML list and add all the XML items? The trouble is, there are other elements tree'd under the list items. These contain forms and images which empty and flicker if the HTML is re-written. The list updates about every second.
|
# ¿ Jun 13, 2009 11:29 |
|
I'm building a class on top of JQuery's $.ajax class. My JSON has a response code that determines which function to call back. code:
|
# ¿ Jul 7, 2012 19:53 |
|
Gordon Cole posted:What are you expecting it to be? The Ajax function? The 'this' keyword refers to the object that contains the function, not the function itself. If you're defining the Ajax function in the global scope then 'this' will refer to the window object. If it was any other object than "Ajax" I could probably re-organise it into my other classes. The trouble is, every ajax request is called this way throughout the code, and sometimes the response function needs to call Ajax().request() which effectively submits the request again. Any other ideas?
|
# ¿ Jul 7, 2012 21:31 |
|
Gordon Cole posted:I'm having a hard time understanding what you're trying to do here and what the problem is. It looks like you're defining the Ajax function in the global scope (on the window object), meaning anything in your program can already access it, but you're also trying to pass it into a callback function. If they can already access the function globally why do they need to get it passed back to them? There are multiple instances of the object. I'm wrapping it because it contains a lot of error handling code that goes beyond simply assigning a standard error handling function; and it allows me to more easily load multiple URLs and keep track of them etc. There are also many instances where the Ajax object is created within other classes. The issue is that I need my response function to be able to access the Ajax object that called it. At the moment I'm trying to avoid doing this: JavaScript code:
|
# ¿ Jul 7, 2012 21:52 |
|
Suspicious Dish posted:What? That's not it at all. Basically, if you call o.f(), o is passed as the this object. If you do var f = o.f; f();, the global environment object is passed (window in a browser context). Closures are not automatically created. But ultimately the response function is always going to call the callback is going to be the $.ajax object. This is why I was trying to store it before hand within the object, so it could get passed. From what I know about prototypes; they're meant to be the default value / function if it's not specified within a specific instance of the class.
|
# ¿ Jul 7, 2012 22:45 |
|
You'll LOVE this... I wrote "var thing = Ajax()" rather than "var thing = new Ajax()" which made "this" evaluate as the window, rather than "self" within the object. Thanks for your help though, guys.
|
# ¿ Jul 7, 2012 23:47 |
|
TildeATH posted:
Just in case you missed it, you are doing this? code:
|
# ¿ Jul 26, 2012 22:51 |
|
I'm just looking into framework programming - specifically Laravel, but I am crap at organising Javascript. Are there any tutorials or advice for separating JS code? Organising the AJAX side of things is easy, since it basically mirrors the API structure. However, the javascript that controls functionality involving manipulating HTML has ended up being an icky mass of numbers of anonymous functions and strings of HTML. Any advice on getting tidy, and organising page-unique HTML rendering into a more readable, less horrific format? (Basically I need a way of linking templated HTML to the AJAX without messy event functions. Updating the HTML is the messiest bit!)
|
# ¿ Jun 23, 2013 12:24 |
|
I need a textarea with bold support, so I'm using a div with contenteditable. Unfortunately, I need to manipulate what's being entered. At the moment, I'm starting with thiscode:
My method, therefore, is as follows: 1) On keypress, setTimeout to the tag replace function to allow the element to accept the keypress event. 2) the timeout function gets the cursor position, makes the html changes, and then reinstates the cursor position. However, in this code, the element loses focus afterwards and afaik, the cursor position is ignored. code:
|
# ¿ Jul 11, 2013 20:13 |
|
This is a Vue.js framework question, so I understand this may not be the perfect thread for it. I am having issues with the scoping of slots. Here's a simple list example. Most Vue tutorials will end up with the HTML on your main page looking like this (pre-render) code:
code:
Before I give up and conform to the ridiculously vague top example, can anyone offer any help here?
|
# ¿ Mar 3, 2017 16:42 |
|
JavaScript code:
JavaScript code:
|
# ¿ Mar 16, 2019 22:20 |
|
Doom Mathematic posted:Actually I think you might be able to get away with eliminating that whole wrapping Promise and just writing this.list.push(func());? That is much simpler, but it doesn't solve the underlying issue sadly. It waits for the first promise, but not subsequent ones.
|
# ¿ Mar 16, 2019 23:17 |
|
Edit: Stil having issues
|
# ¿ Mar 17, 2019 01:00 |
|
|
# ¿ May 6, 2024 03:06 |
|
necrotic posted:Are you calling this as await obj.add or just plain obj.add? The latter won't work here, calling an async function spawns a new promise and if you do not wait on that promise it may not be invoked before the next time you call obj.add. I'm not awaiting because add() is typically an event-emitted callback. I have given up and I'm now using an npm package called easy-promise-queue. Thanks though
|
# ¿ Mar 17, 2019 17:29 |