Reusing the same v-app in vue - vuejs2

I have the below pug/html:
table.accountinfo.table.table-sm
thead.thead
tr
th #
th Name
th Address
th Balance
tbody
tr(v-for="account in accounts")
td {{account.accountID}}
td {{account.name}}
td
span(title='{{account.accountAddress}}').ellipsisoverflow {{account.accountAddress}}
td
span {{account.balance}}
table.accountinfo.table.table-sm
thead.thead
tr
th #
th Name
th Address
th Balance
tbody
tr(v-for="account in accounts")
td {{account.accountID}}
td {{account.name}}
td
span(title='{{account.accountAddress}}').ellipsisoverflow {{account.accountAddress}}
td
span {{account.balance}}
And the below vue script:
var accountinfo = new Vue({
el: '.accountinfo',
data: {
accounts: []
}
});
When I open my html file only the first table is correctly created (mutiple rows with the correct data). The second table however is not created correctly and shows the values including the brackets (and thus are not replaced bye vue). I assume this is the case as the same v-app is used twice. How can I configure this so both elements/tables are correctly created using the same v-app?

I don't think it's written specifically anywhere but as per the docs linking is done with ids, this is to ensure that one vue instance is only linked to 1 root element.
It's not possible to mount 1 app on multiple elements.
In line with your edit, you have a couple of ways to do what you want:
Change the selector for the second form and register another Vue instance with that Id.
Have one wrapping container that the Vue instance is registered to then each table can read from the same accounts variable.

Related

Materialize select element will not show passed options (empty ul)

My question is probably really easy. I want to populate a Materialize select element with a few options. I don't want to put my options in the HTML, I want to do it from a JSON with javascript (I get the json from a different service). In my HTML file, I just have an empty select.
In the documentation, I see that during the select initalization, you can pass an options object. I assume this can be used to populate the select dropdown. A bit lower it is stated that the correct key is dropdownOptions, and you are supposed to pass an UL to it. I did so, but the UL is empty. Console log shows that the ul is built correctly. What am I missing?
let ul = document.createElement("ul");
arr.forEach(oddelek => {
let li = document.createElement("li");
li.appendChild(document.createTextNode("Four"));
ul.appendChild(li);
});
console.log(ul); // looks good
M.FormSelect.init(selects, {
"dropdownOptions": ul
});
What could be the reason that only an empty ul appears?
Because the above code didn't work, I decided to just add the elements to the HTML with javascript, and then run the init with an empty options object. But it doesn't work, the dropdown is still empty.
The init with empty options object works perfectly if the items are added manually in the html, but does not work if they are added through javascript. I have no idea why, I call the init after I add the elements. Inspecting the resulting html without the init looks just like in the documentation. Any advice?

Selenium WebDriver WebTable getData: How to get a value of "td" if it is depends on another "td"

I am facing one issue where the value of a one particular cell(td) in a webtable depends on another cell (td)..
Example:
Use http://www.espncricinfo.com/new-zealand-v-australia-2015-16/engine/match/914239.html and click on Full score...
Now I want to get a batsmen name who is unbeaten (Need "Not out" batsman from New Zealand 1st Innings. In this case "TA Boult")
But "TA Boult" and "Not out" are 2 different td's of a same "tr".
Can someone please guide me how to achieve this?
The following XPath would solve this issue for you:
//table[contains(#class,"batting-table")][1]//td/a[.="TA Boult"]/../../td[#class="dismissal-info" and contains(text(), "not out")]
You may want to make the selector for the top table a bit more specific, but essentially this XPath is doing the following:
Find the first table that contains the classname "batting-table"
Get all the td elements within this table
Get all the a elements within the td elements
Specify that the a element's text must be the player you are searching form, in this case, TA Boult.
Use /../.. to select the parent of the parent of the a element that has the text "TA Boult". So if the parent of the a tag is td, the parent of the td tag is tr.
Now that we are in the row containing any matching a tags, we can search within this row for the td tag with the "dismissal-info" class that contains the text "not out".
From there you could then use /../.. again to return the entire row as the result of the XPath.
So essentially, you are searching for a row, then searching for a child, then searching for a parent, then searching for a different child and then returning a correct row.
Hope that helps!
Ok so...
//all tr elements.
IList<IWebElement> tableTRCollection = driver.FindElement(By.Xpath("//table[#class='batting-table innings']")).FindElements(By.TagName("tr"))
//in every tr all td elements will be:
IList<IWebElement> tableTDCollection;
foreach(IWebElement tr in tableTRCollection )
{
tableTDCollection = tr.FindElements(By.TagName("td"));
}
//in td collection take all td
foreach(IWebElement td in tableTDCollection )
{
string tdText = td.Text;
}
and so on...
after you get all the collections you can get everything.
Thank you all for answers.. I was able to find an answer after a lot of struggle, but found solution is almost same that Ben has suggested.
I did not try another suggested solution though..
Below is the code...
WebElement name = driver.findElement(By.xpath(".//*[#id='full-scorecard']/div[2]/div/table[1]//td[#class='dismissal-info'][contains(text(),'not out')]/ancestor::tr/td[#class='batsman-name']"));

How to handle div that is created dynamically in a table

I am trying to iterate a table to get the results. The structure of the table looks as mentioned in the picture
When I open the page, there is only one with role="presentation" and I am able to retrieve the data using the below css locator.
driver.findElement(By.cssSelector("div[id^=dojox_grid__View_] div.dojoxGridContent div.dojoxGridRow:nth-child(1) tbody tr:nth-child(1) td:nth-child(6)")).getText();
When I scroll the page manually another tag is created dynamically with role="presentation" and has many rows(div.dojoxGridRow). I want to iterate these rows too.
Selenium is able to go only to first level (first ) and get the details. I am not sure how to reach the second level
I'm not sure about which element you're trying to access.
But you can access to all div with 'presentation' role (return a list):
driver.findElements(By.cssSelector("div[role='presentation']"));
If you're trying to access to each row under div with role presentation:
driver.findElements(By.cssSelector(".dojoxGridRow"));
If you want to get rows child of div with role 'presentation':
List<WebElement> presentations = driver.findElements(By.cssSelector("div[role='presentation']"));
for (WebElement presentation : presentations) {
List<WebElement> rows = presentation.findElements(By.cssSelector(".dojoxGridRow"));
// DO SOMETHING...
}
Hope that helps.

how can i delete a div that i created with dojo?

i create a div with heading and UL inside with dojo.create. how can i totaly delete this div with heading and UL children so that i can create a div with this id again (with different content)?
I create the div like this (i delete some attributes and the h1 and ul creation because it was too much code, i do it the same way like i create the div):
var newAlarmDiv = new dojox.mobile.ScrollableView({
id: "divAlarms",
dojoType: "dojox.mobile.ScrollableView",
});
newAlarmDiv.placeAt('mobileView','first');
i already tried it with the dojo.destroy command but when i create a new div after destroying it i get many different errors so it seems not to be deleted correctly.
How do i correctly "undo" the div creation?
greets
Tom
You are creating a "Widget", which has DOM elements associated with it. If you were destroying only dom elements you would use dojo.destroy.
Since you want to destroy the widget, you should use destroy or destroyRecursive. The API Docs have a good overview of what each method does.
var scrollableViewWidget = new dojox.mobile.ScrollableView({/*params*/});
scrollableViewWidget.placeAt('someDiv','first');
scrollableViewWidget.destroyRecursive();

Can we have nested targets in Dojo?

I have two divs nested under a parent div and I want all these to be source as well as targets for dojo.dnd.
I want to be able to add nodes to the div over which the content was dropped and also allow the user to move this in between the 3 divs.
Something like this -
http://www.upscale.utoronto.ca/test/dojo/tests/dnd/test_nested_drop_targets.html
This is I gues implemented in older version of Dojo and doesn' seem to work with 1.4
Is the support for nested targets removed? Is there any way to achieve this?
Nested sources/targets are not supported currently. In most cases you can work around this restriction by using independent sources/targets, yet positioning them as you wish with CSS.
I used a workaround for this case. I create another DIV element which positioned at the same place of the nested target with same width and height but with higher z-Index value. Then the new DIV element covers the nested target. When user is trying to drop on the nested target, he actually drops to the above new DIV element. As long as the new DIV element is not nested in the parent drop target, Dojo's dnd operation works well. I usually put the new DIV element as a child of the body element.
What you need to do is to create the new DIV in onDndStart and destroy it in onDndCancel, then everything should work well.
Dojo version 1.10 still does not support nested Dnd.
CSS positioning and overlay div's didn't work for me. But I noticed that dragging an element out of a dndContainer into a parent dndContainer doesn't trigger onMouseOverEvent for the parent.
In case someone is still using dojo and has the same problem, here is my approach to solve this:
Declare your own dndSource e.g. nestedDndSource.js
define([
"dojo/_base/declare",
"dojo/dnd/Source",
"dojo/dnd/Manager"
], function(declare,dndSource, Manager){
var Source = declare("dojo.dnd.Source", dndSource, {
parentSource: null,
onOutEvent: function(){
if(this.parentSource != undefined)
Manager.manager().overSource(this.parentSource)
Source.superclass.onOutEvent.call(this);
}
});
return Source;
})
Use that nestedDndSource for the children instead of dojos and make sure to provide the dndSource of the parent as parentSource-Parameter:
var parentDndSource = new dojoDndSource(parentNode, {..});
var childDnDSource = new nestedDndSource(childNode,{
parentSource: parentDndSource,
onDropExternal: ...
});
Working example: https://jsfiddle.net/teano87/s4pe2jjz/1/