I'm trying to build an HTML list using kotlinx.html by iterating over a collection, for each element in the collection I want to build an LI tag inside a UL tag.
This is what I'm trying:
fun showProducts(products: List<Product>) {
document.getElementById(content.id)
?.append {
ol {
products.forEach {
this.li {
+it.name
}
}
}
}
}
But I get an error in browser console:
Uncaught (in promise) TypeError: closure$products.iterator is not a function
How can I iterate over the collection and add LI tags inside the UL tag for each product passed to the function?
maybe, instead of to use products.forEach, you can use a simple for (p in products). So the code will be:
fun showProducts(products: List<Product>) {
document.getElementById(content.id)
?.append {
ol {
for (p in products) {
li {
+p.name
}
}
}
}
}
see this link:
https://try.kotlinlang.org/#/Kotlin%20Koans/Builders/Html%20builders/Task.kt
Related
I am working on a shopify integration, and I am trying to perform some bulk queries which return data in jsonl format.
I read carefully the documentation, and I understood which is the principle behind this format, but there is one thing I don't understand: the following is a portion of my jsonl file representing the first item in the result
{"id":"gid:\/\/shopify\/Product\/6755349070004","options":[{"id":"gid:\/\/shopify\/ProductOption\/8677003133108","name":"Città ","position":1}],"title":"Product title","productType":"Concerto Live"}
{"id":"gid:\/\/shopify\/ProductVariant\/40163436363956","price":"100.00","title":"MIlano","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/ProductVariant\/40163436396724","price":"100.00","title":"Roma","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/ProductVariant\/40163436429492","price":"100.00","title":"Firenze","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/Collection\/272323707060","description":"Product variant description","title":"CONCERTI","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/Collection\/272323739828","description":"Product variant description","title":"LIVE","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/Collection\/273036607668","description":"Product variant description","title":"Product variant description","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
and it's obtained by the following query
mutation {
bulkOperationRunQuery(
query: """
{
items: products{
pageInfo {
hasNextPage
}
edges {
cursor
node {
id
variants(first: 10) {
edges {
node {
id
price
title
}
}
}
options(first: 5) {
id
name
position
}
title
collections(first: 8) {
edges {
node {
id
metafields(first: 5) {
edges {
node {
id
key
namespace
value
}
}
}
description
title
}
}
}
productType
images(first: 2) {
edges {
node {
src
}
}
}
}
}
}
}
"""
) {
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}
So The first line it the "main" product object, the lines 2,3 and 4 are the variants, then we have the collections and then the image: the problem is that, besides the parent's id, there is no way to know which parent's property a child line refers to. If I want to build back a json from this, how can I know for example that the second line is an item of the array in products.variants?
You can use either:
the id format (gid://shopify/Product/6755349070004 is a product)
the __typename property that exists on all GraphQL objects
I try to click html css 'a' but I cant access to it. How can I to do?
at test
waitFor { myelement.displayed }
myelement.click()
class test extends Page {
static at = { title == "test page" }
static content = {
myelement {$("a", id: "myid")}
}
}
You should be able to access it directly using the ID. I think your syntax is incorrect, try using the ID selector instead: $("#myId")
Using AureliaCLI and TypeScript.
I have a service which returns a specific type and a component which incorrectly assigns the returned object to a variable of another type:
import { ItemService } from "./itemService";
import { Item } from '../server/backend';
export class ItemDetails {
item: Item = null;
constructor(private itemService: ItemService) {
}
activate() {
this.item = this.itemService.getItem();
}
}
and
import { Seat } from "../server/backend";
export class ItemService {
item: Seat;
constructor() {
this.item = null;
}
getItem(){
return this.item;
}
setItem(item: Seat){
this.item = item;
}
}
This will generate an error when 'au run --watch' is run the first time, but any subsequent change to either file does not produce an error.
Can I configure AureliaCLI to look at dependant files also?
Thanks
Right, as you can probably guess, I am new to TypeScript.
I forgot to add a return type to the service method...
This will cause the error to be triggered:
getItem(): Seat {
return this.item;
}
I want to write tuned version of TableView (TableView.qml in Qt package).
I have ColumnDescriptor.qml with column definition:
Item {
property string title
property var formatDelegate: null
.... (other property definition)
function format(val) {
if (formatDelegate != null)
return formatDelegate(val);
else
return val;
}
}
The above code defines set of properties and fuction format(val), that calls for format value if formatDelefate was set.
In the main table I use list to store predefined columns definition (temporaly) and ListModel to store final columns definition ( the latter is more useful than list in remaining implementation)
list example:
property list<ColumnDescriptor> colDefines: [
ColumnDescriptor {
title: qsTr("col1")
},
ColumnDescriptor {
title: qsTr("col2")
formatDelegate: function(val) { return "!" + val}
}
]
Filling ListModel (id: columnModel):
Component.onCompleted: {
for(var i = 0; i < colDefines.length; ++i)
{
var col = colDefines[i];
...(some calculation)
columnModel.append(col);
}
}
All looks fine, but when I try to call format from model item, Qt sends me the following error
Property 'format' of object QQmlDMListAccessorData(0x8e3bf78) is not a function
Example of calling format:
Repeater {
model: columnModel
Text {
text: model.format([SOME USEFUL DATA])
}
}
On the other hand, if I call format directly from list it works well.
So my question here is how to fill model in a way that the format or other function will work correctly when being called from model?
For QtQuick2 this should work
formatDelegate = [function(val) { return "!" + val}]
formatDelegate[0]("some text")
but you could also use an overriding technique:
Item {
function formatDelegate(val) {
return val;
}
function format(val) {
return formatDelegate(val);
}
}
ColumnDescriptor {
function formatDelegate(val) {
return "!" + val
}
}
This way Item.format() should call "return val" as default and "!"+val for ColumnDescriptor given that ColumnDescriptor is derived from Item.
Try this
Repeater {
model: columnModel
Text {
text: columnModel[index].format([SOME USEFUL DATA])
}
}
This is the first time I'm finding the & parent selector extremely useful so that I don't need to redefine parents simply to modify a child element.
Of course this is actually easy with LESS, but I have to ask!
<div id="skrollr-body" class="nonav">
<div class="skrollable">
</div>
</div>
#skroller-body {
.skrollable {
margin-top:40px;
.nonav & {
// this parent selector lets me modify
// .skrollable without duplicating it
margin-top:0px;
}
}
}
The output of .nonav & is
.nonav #skroller-body .skrollable
I'm wondering if I can get #skroller-body.nonav .skrollable instead somehow without extra HTML markup (a wrapper div.nonav)?
Currently I'll just duplicate the parent
#skrollr-body {
margin-top:40px;
left:0;
width:100%;
.skrollable {
margin-top:40px;
position:fixed;
z-index:100;
.skrollable {
position:absolute;
.skrollable {
position:static;
}
}
}
&.nonav {
.skrollable {
margin-top:0px;
}
}
}
Or to save redundant output;
#skroller-body.nonav .scrollable { margin-top:0px; }
But the whole point here is CSS code that's easy to maintain and read.
The docs tell us:
The & operator represents the parent selectors of a nested rule and
is most commonly used when applying a modifying class or pseudo-class
to an existing selector
So:
#skroller-body {
&.nonav {
.skrollable {
// stuff
}
}
}
}