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 5 years ago.
Improve this question
Let's say I have a HTML table with 5k rows and 50 columns (generated from JavaScript object) and I would like to send 50 checked rows (checkbox) from client to server using HTTP (JSON). What would be more efficient? Iterating in HTML to find the checked rows or iterating trough my JavaScript object to find corresponding rows?
fields = columns (50)
values = rows (~5k)
JavaScript data object:
parent {
child: [{field1: value1, field2: value2, field3: value3, and so on...}]
}
I'm not sure what you are trying to do with this information, but interacting with the DOM is one of the slowest things you can do, so you should check the JavaScript objects.
While you generate each row, you keep a reference of the checkbox and you bind it to your data in a javascript object.
Then you add an event listener on the checkboxes: when you tick on or off a row, you push or remove the mapped data line in an array that will always be up to date and ready to be sent.
Related
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 5 years ago.
Improve this question
I have a firebase database where a node structure is like this.How do I insert/update data from a web page using javascript? I want to insert data individually in promo_ar,promo_en and promo_fr.
I am new in firebase and the help will be much appreciated!
You must do it this way
firebase.database().ref('Promotions/promo_en').set({
desc_promo: value,
name_promo: value
});
Remember that using set, you update elements of a node of your database, on the other hand, when you perform this type of updates, you must send both elements to update within that node, if you omit any element, it is removed from your base, for example...
firebase.database().ref('Promotions/promo_en').set({
desc_promo: value,
});
In this case, only desc_promo is being updated, thus eliminating the rest of the node elements.
in the same way you can insert new nodes in an element like this
firebase.database().ref('Promotions/promo_es').set({
desc_promo: value,
name_promo: value
});
in this way we add the Spanish language to the Promotions node
AGGREGATE:
you can have as many nodes as you want below a main node, remember that if you are going to update the final node, it does not affect the higher ones, but the higher node does affect the lower ones, for example
firebase.database().ref('Promotions/promo_es/exchange').set(
{
desc_promo: value,
name_promo: value
}
);
Promotions
|_>promo_es
|_>desc_promo : value
|_>name_promo : value
|_>exchange
|_>desc_promo : value //<-this is updated or created
|_>name_promo : value //<- this is updated or created
now if you edit the Promotions / promo_es node without including its sub nodes, these will be eliminated, you can perform the tests that you deem convenient in firebase to polish the method to use in your system
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 6 years ago.
Improve this question
I have a csv file that looks like this:
Name, Data1, Data2, Data3,...
Name_1, Data1_Value1, Data2_Value1, Data3_Value1,...
Name_2, Data1_Value2, Data2_Value2, Data3_Value3,...
and so forth.
Instead of plotting the data like in this Example
I would like to use only the first row of data. With the Column Names as the labels.
Is there a way to accomplish that?
Any help is very much appreciated.
The first row is simply index 0 of the resulting data object returned from d3.csv:
d3.csv("data.csv", function(d){
console.log(d[0]); //<-- this is the first row
});
One a side note, remove the spaces after the comman from your csv file, they are not necessary.
EDITS
You'll need to transform the data. Simple approach is:
var newData = [];
for (var key in data[0]){
if (key != "Name"){
newData.push({
name: key,
value: +data[0][key]
})
}
}
Working sample here.
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 have a php file that set an array of values and a table into a html page. I would like to insert the php data into this table with a limit 15 of rows so when the data reaches the limit, continue on an adjoining table:
Could JQuery be a good option to get this?.
Yes, if those data change dynamically, using jQuery would be a good solution.
i believe it would be faster, if you directly divide it using php.
here is a piece of code for your problem.
//assuming this is your database retrieval
$tableArr = array();
for($i=1; $i<=50; $i++) {
$tableArr[] = '<tr><td>'.$i.'</td><td> Name '.$i.'</td><td> Type'.$i.'</td></tr>';
}
//chunked or divided data
$dividedArray = array_chunk($tableArr, 15);
$dataTable = "";
$commonHeader = '<thead><tr><th>ID</th><th>Name</th><th>Type</th></tr></thead>';
foreach($dividedArray as $indDividedTable) {
$dataTable.= '<table border="1">';
$dataTable.= $commonHeader;
$dataTable.= implode("\n", $indDividedTable);
$dataTable.= '</table>';
}
echo $dataTable;
Not sure if you mean by "adjoining" literally "next to it" but I've used jQuery Datatables for pagination of data and it has worked out well. You may want to modify your PHP to output the data into a JSON format, or perhaps even make the data-fetch a separate query back to the server.
What does adjoining means? If you mean pagination, jQuery surely can do this using AJAX. I'm using jQuery plugin datatables
to retrieve data from PHP with JSON format. It has table pagination by default.
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 8 years ago.
Improve this question
I have a javascript in the html to render the html on client. I know how to do it using JSON. My question is: Is it possible without JSON?
For example, my server will reply array such as [["good", "bad"],["first", "second", "third"]] using a servlet. I mention String array in topic, because the xmlhttp.responseText is regarded as a text or string. So in javascript, how do I convert this result into array variable?
Using JSON, my server has to reply
{
"1": ["good", "bad"],
"2": [....]
}
I just wanted to see whether we can avoid this key string.
As already pointed out in the comments, JSON has quote:
two primary data structures: ordered lists (recognized as 'arrays')
and name/value pairs (recognized as 'objects')
JSON objects are written inside curly brackets and can contain multiple key/value pairs.
JSON arrays are written inside square brackets (elements of the array can be basic types like number or string but also objects or arrays).
(from http://www.w3schools.com/json/json_syntax.asp)
So [["good", "bad"],["first", "second", "third"]] is in JSON format and doesn't need to be converted to an object.
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 9 years ago.
Improve this question
I have the following field,
<input id="department" value="finance"/>
I'm trying to create an object variable containing the field in plain old javascript like so.
var $field = $(document.getElementById("department"));
I'm then trying to pull the value from the field variable, however it's failing.
$field.value;
Does anybody know what I'm doing wrong?
That looks like a jQuery object, which is a collection of DOM elements, and the value property is attached to the DOM elements.
You should have:
var field = document.getElementById("department");
// now you can access field.value
jQuery objects have a val() method that gets you the value of that property:
var field = $('#department');
// here you can call field.val();
Lose the call to $() if you want a DOM element, and not a jQuery object:
$field = document.getElementById("department");