Save only modified elements of an array [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am working with Angular, C# for the backend and DB with Oracle. The project is for a company and in the grids they leave me more than 120 records. In these grids the user can edit each record and by selecting the "Save" button all the records are sent (those that have been modified and those that have not been modified) and that is where I need your help. How can you tell which records have changed? MY IDEA is to make a copy of the data that arrives and at the end compare which ones have been changed and send that new list to the database (only with the changed records). ANOTHER IDEA is that every time someone makes a change, it will be added to another list, but the problem with this is how to identify when it changes and when it changes and returns to how it was ... Any ideas?

There are numerous ways to keep track of which elements have been modified:
Define an interface with the object and an "isModified" flag. As each item is modified, turn that flag to true.
Keep a separate list of modified objects (as you mentioned)
Keep a list of the Ids of the modified objects
With regard to how to determine whether an object has been changed, that will depend on how you are handling the edits. If you are using Angular Forms (as mentioned by #nobalG above), then it will tell you went the data is modified.
If not, again depending on how you are handling the edits, you may have other changed events you can track.
More detail isn't possible without having some code detailing how you are handling the edits.

Related

Update value of nested array in firebase database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm building a web app with Vue.js using Firebase authentication and real time database, which I'm new to.
In this app the user answers to questions to achieve some points.
My problem is: I want to update an existing array already stored and created in the database so that the progress/points of that user will be under track to update all the components in my app.
For example let's say I want to increase +1 the highlighted value in the screenshot:
I was thinking about something like userid.progress[6][0] += 1 like in normal javascript, but I can't update the database, value still at 0.
I've read something about .set() or .update() but in that case I should rewrite all the array (and it would be a problem), but I might be completely wrong.
PS: it's not a problem about getting the user id or the current user, everything is working fine.
Hope to find someone to help me, thank you so much in advance!
If you're trying to update an existing score, you can write on the most granular level. So:
ref.child("pjoCy...0tl3/progress/0/6/0").set(1)
If you want to push a new score to the end of the array, you'll indeed need to read the entire score array to add a new value to the end. This is one of the many reasons why Firebase recommends against using array indices like you do. If you instead us so-called push-IDs, adding a new value becomes as easy as:
ref.child("pjoCy...0tl3/progress/0/6").push(1)
I recommend reading more about structuring lists in the Firebase documentation and the classic blog posts on handling arrays in Firebase.

Button that updates number on all sessions [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I've tried a lot of ways, like for example the fs module, but I just can't find out how to implement this. I need a button that:
Updates by one whenever any user presses the button
Persists on the server
Does anyone know how to do this?
If you are new and need to build something that stores stuff on the server you have a lot to learn. If you just need to solve this simple problem and get things working you could make huge progress using a hosted backend service. If you do this you can write a couple of lines in JS and the job will be done. Most offer a free account.
One such service is built.io see link below:
https://docs.built.io/api-reference
var project = Built.App('blt5d4sample2633b').Class('score').Object();
project = project.increment('points',10); //Increases points field value by 10
That code above would update the score by 10 and store it , you can then retreive it when you show the page. All users would see the score update.
There are realtime backend services too which are very good.
An example is:
www.firebase.com
You would need to decide which one is best for you, add their script to your page add a button, hook the click event upto a function that you would then add the simple code to update the score. See above.
It a nutshell that would be it. You can probably get it working in under 1 hour if you follow the guides on the vendors site.
Firebase is backed by google and has a huge online community.

How to store Records (json) on webpage and show only on record on View [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have 10 records in json array that comes from api call. But I need to show only 1 record on webpage providing next and previous buttons. So when user clicks on next or previous buttons I need to fetch the next or previous records and display on webpage. Something like viewpager in android or flipview in windows apps.
The reason why I want to store is just to avoid unnecessarily api calls to server fetching record and also pointers to next and previous record.
Is it possible to store those 10 records in some javascript variable and keep iterating when user clicks on next and previous.
Server side I am using laravel 5.2
Of course it can be done. Just format your JSON correctly to hold an array of records, and maintain an index pointing to the current record.
To update the display you can either use pure JavaScript or utilize some kind of MVVM library (for example) like Knockout or Angular.

PHP saving and re fetching checkbox values [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am an electronic engineering student. I have a doubt concerning Web development. I have to make a web site for doctors to enter patients data. Most of the data are in check box format. My question is regarding saving and re fetching check box status from the data base, so that the user can see what all are checked previously and what all are not checked when he log's in back the next time.
And also how can i replace the check-box status in database if i change the status. I searched about this in internet but there is no much data concerning this. So if anyone could guide me or give me a link or example codes where i can look and study, it will be a great help for me.
You can save the values of a particular check box in many different way and there are tons of resources online for this, I am sure you have come accross this information before.
You could save your check box values as a string with a string delimiter, for example: A-B-C-D-E. This was you can split/explode the string whenever you need to retrieve the values again as an array and appropriately mark the corresponding check boxes once they sign in again.
Some Resources: http://www.html-form-guide.com/php-form/php-form-checkbox.html
send checkbox value in PHP form

User Defined Rules in a Web Application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm required to implement a notification system integrated to a web application (JavaScript + PHP). Notifications should be fired based on user-defined rules. I don't have experience with rules engines and building rules. Therefore, I don't know what I'm doing or if what the following could be implemented by better solution.
I'm trying to figure out how to store and process the following hypothetical scenario. Let's say that the web app is a shopping online service for a store that has 3 lines of products, line A, line B and line C. Each line has different characteristics. User#1 selects an object from line A, then specifies some characteristics such as size and colors. User#2 selects an object from line B, the only characteristic for this kind is material, he selects wood. Then both users ask system to notify them whenever these objects with these characteristics become available.
From what I've read so far, this could be done through [user-defined rules]. If so, then
What's the best technology to handle it? I'm willing to learn but I need a direction to help me start.
Can I use openRules or similar for this?
How to sent user defined data to a web service? given that they change based on the line.
If you are using a database, or anything similar, you can make a table where you would save the rules for each user. You can than later load them with a php class as soon as the user logs in, and check against them before doing anything that was optional.
You can also make a table and set flags, once an item becomes available loop trough the table and notify every user waiting. You would need to store, item id and customer id, in the table and delete them once they have been notify.

Categories