I have some script that is delivering a series of rows from an SQL database.
I want to append.() a button to each row. My current code is:
tx.executeSql('SELECT * FROM myprogram', [], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
$('#myprog').append(results.rows.item(i).event)
$('.event').append('<button class="save_event">Remove</button>');
}
});
But the buttons get doubled up. For example if I get 3 rows, the first row will have 3 buttons, the 2nd will have 2 and the last will have 1 button.
Can anyone help me out to have the buttons display only once per row?
Thanks!
I found the answer, quite simple:
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
$('#myprog').append(results.rows.item(i).event).append('<button class="remove_event">Remove</button>');
}
$('#myprog').append(results.rows.item(i).event).append('<button class="remove_event">Remove</button>');
You need to append to $('#myprog') selector.
Related
A =[0,0,0,0,0] if I select 1 element and increment it by 1, so the should that to become new array A=[0,0,1,0,0] and when I also select another element and increment it then the new array may become A=[0,1,1,0,0] and so on. the increment is done by button, the increment may not only be 1 times.
in short is to make a counter for each of the random selected element and update the array anytime
Your question is rather an JS question than an react-native.
Below is an sample:
let numbers = [0,0,0,0,0]
const max = numbers.length
function replaceArrayElement (values, index) {
return ([...values.slice(0, index), values[index]+1, ...values.slice(index+1)])
}
function getRandomInt() {
return Math.floor(Math.random() * max);
}
for(var i = 0; i<=10; i++){
numbers = replaceArrayElement(numbers, getRandomInt())
}
console.log('numbers: ',numbers)
When there isn't enough space left on a page, merged rows (cells) in table are placed into a new page.
How to prevent this and assure the table is filling the free space on the current page?
Section section = document.AddSection();
Table t5 = new Table();
t5.AddColumn(Unit.FromCentimeter(4));
t5.AddColumn(Unit.FromCentimeter(4));
Row first = t5.AddRow();
first.Cells[0].AddParagraph("Header 1");
first.Cells[1].AddParagraph("Header 2");
for (int j = 0; j < 4; j++)
{
var rowpd = t5.AddRow();
rowpd.VerticalAlignment = VerticalAlignment.Center;
rowpd.Cells[0].MergeDown = 17;
rowpd.Cells[0].AddParagraph("Merged 18 cells. ");
for (int i = 0; i < 18; i++)
{
if (i == 0)
{
rowpd.Cells[1].AddParagraph($"value {i}");
}
else
{
var row = t5.AddRow();
row.Cells[1].AddParagraph($"value {i}");
}
}
}
document.LastSection.Add(t5);
MigraDoc does not (yet) split cells, it only splits between cells. With MergeDown you create a huge cell that will not split.
Option: Avoid the MergeDown and use many small cells on the left column without horizontal borders to achieve a similar optical effect, but with page breaking as expected. Depending on the text in the left column this may or may not be an option.
I have a question on this code.
It's the code for finding delay.
in order to estimate the delay,
in my mind,I should find the largest value from the array mean_bit_counts[], but in the picture, they choose the smallest one. So could you solve my problem? Thanks!
// Find |candidate_delay|, |value_best_candidate| and |value_worst_candidate|
// of |mean_bit_counts|.
for (i = 0; i < self->history_size; i++) {
if (self->mean_bit_counts[i] < value_best_candidate) {
value_best_candidate = self->mean_bit_counts[I];
candidate_delay = I;
}
if (self->mean_bit_counts[i] > value_worst_candidate) {
value_worst_candidate = self->mean_bit_counts[I];
}
}
valley_depth = value_worst_candidate - value_best_candidate;
I have application where there is a dynamic web table, I want to select multiple check box for matching value in one of column.
Refer attached image:
Here is what I've tried so far:
List<WebElement> Rows = s.findElements((By.xpath("//a[text()='Nitesh Kumar']")));
System.out.println("No of rows = "+Rows.size());
int z=Rows.size();
int i =0; for(i=0;i<z;i++)
{
for (int j = 0; j < Rows.size(); j++ )
{
s.findElement(By.xpath("//a[text()='Nitesh Kumar']/../../td[1]")).click();
}
}
Change the xpath to
//table[#id='id of the table']/tbody/*/td[3]/a[text()='Nitesh Kumar')]
to find the elements from the table.
Once the elements are found get the size of the list and use the below xpath to click the check box
//table[#id='id of the table']/tbody/*/td[3]/a[text()='Nitesh Kumar')]../td[1]
The complete code would be something like below.
List<WebElement> Rows = s.findElements((By.xpath("//table[#id='id of the table']/tbody/*/td[3]/a[text()='Nitesh Kumar')]")));
System.out.println("No of rows = "+Rows.size());
int z=Rows.size();
int i =0;
for(i=0;i<z;i++)
{
for (int j = 0; j < Rows.size(); j++ )
{
s.findElement(By.xpath("//table[#id='id of the table']/tbody/*/td[3]/a[text()='Nitesh Kumar')]../td[1]")).click();
}
}
I am having two drop down menus. The First Drop Down is called Events and Second Drop Down is called Attributes.
And Events are 47 in numbers and Each corresponding event has 4 attributes.
Now the problem is, I want to write a code like - select the first event and print its corresponding attributes. Similarly select the second event and print all its attributes. All of this should be in a loop.
Please help me on this. Please show me a sample code part.
You can try the below code. Let me know if it works.
for (int i = 0 ; i <47 ; i++)
{
Select event_DropDown1= new Select(driver.findElement(By.id("<ID for event_DropDown1>")));
event_DropDown1.selectByIndex(i);
Select attributes_DropDown2= new Select(driver.findElement(By.id("ID for attributes_DropDown2")));
/* Getting all options from the Attributes dropdown */
List<WebElement> options = dropdown.getOptions();
/* Loop to print one by one all the options */
for (int j = 0; j < 4; j++)
{
System.out.println(options.get(j).getText());
}
}