I've started messing with Polymer and I've done the basic tutorial with the social media cards. In it several cards care looped over as repeat="{{post in posts}}". What I would like to do is something like repeat="{{post in range 1...10}}". Ultimately I'd like to use a published property cols to provide a max value instead of 10. I've been able to get something like this working by setting the cols property to something like [1,2,...,9] but that is unreasonable to any large set of values. I've also expanded on this by using the ready function and executing this.colsAr = new Array(cols), then in the repeat `{{col in colsAr}}.
What is the best/correct method of looping over a variable number of elements where the number is determined by a property?
To add to this lets also say the cols property is dynamically changed via a select input. This should cause a re-draw when a new value is selected.
Generally the best way to do this is to use a computed property to express your filtered Array.
Something like this:
<template repeat="{{post in slice}}">
...
computed: {
slice: 'sliced(posts)'
},
sliced: function(posts) {
return posts.slice(1, 3);
}
However, right now, the computed property engine doesn't automatically ArrayObserve posts, so we have to manually force a re-compute when the Array structure changes.
kick: 0,
computed: {
slice: 'sliced(posts, kick)'
},
sliced: function(posts) {
return posts.slice(1, 3);
},
postsChanged: function() {
this.kick++;
}
Incrementing kick forces the data engine to recompute slice (gives it a kick). Fwiw, we are trying to improve this particular situation, but the above technique should work in the short term.
Working example:
http://jsbin.com/dadeto/3/edit
Related
As far as I understand, it is not possible in Appian to dynamically construct (process) variable names, just like you would do e.g. with bash using backticks like MY_OBJECT=pv!MY_CONS_`extract(valueOfPulldown)`. Is that correct? Is there a workaround?
I have set of Appian constants, let's call them MY_CONS_FOO, MY_CONS_BAR, MY_CONS_LALA, all of which are e.g. refering to an Appian data store entity. I would like to write an Appian expression rule which populates another variable MY_OBJECT of the same type (here: data store entity), depending e.g. of the options of a pull-down menu having the possible options stored in an array MY_CONS_OPTIONS looking as follows
FOO
BAR
LALA
I could of course build a lengthy case-structure which I have to maintain in addition to MY_CONS_OPTIONS, so I am searching for a more dynanmic approach using the extract() function depending on valueOfPulldown as the chosen value of the pulldown-menu.
Edit: Here the expression-rule (in pseudo-code) I want to avoid:
if (valueOfPulldown = 'FOO') then MY_OBJECT=pv!MY_CONS_FOO
if (valueOfPulldown = 'BAR') then MY_OBJECT=pv!MY_CONS_BAR
if (valueOfPulldown = 'LALA') then MY_OBJECT=pv!MY_CONS_LALA
The goal is to be able to change the data store entity via pulldown-menu.
This can help you find what is behind your constant.
fn!typeName(fn!typeOf(cons!YOUR_CONSTANT)).
Having in mind additional details I would do as follows:
Create separate expression that will combine details into list of Dictionary like below:
Expression results (er):
{
{dd_label: "label1", dd_value: 1, cons: "cons!YOUR_CONSTANT1" }
,{dd_label: "label2", dd_value: 2, cons: "cons!YOUR_CONSTANT2" }
}
on UI for your dropdown control use er.dd_label as choiceLabels and er.dd_value as choiceValues
when user selects value on Dropdown save dropdown value to some local variable and then use it to find your const by doing:
property( index(er, wherecontains(local!dropdownselectedvalue, tointeger(er.dd_value))), "cons")
returned value of step 3 is your constant
This might not be perfect as you still have to maintain your dictionary but you can avoid long if...else statements.
As a alternative have a look on Decisions Tables in Appian https://docs.appian.com/suite/help/21.1/Appian_Decisions.html
I am trying to create an index that returns entire data object of the documents in a collection;
here is the code:
CreateIndex({
name: "users_by_data",
source: Collection("users"),
values: { field: ['data'] }
})
but after creation it says: Values Not set (using ref by default)
If I specifically define fields (separately by their name), it will behave as expected, but data isn't working. the question is:
Is it impossible (e.g. for performance reasons) or am I doing it wrong?
side note: I am aware that I can do Lambda function on Paginate and achieve similar result, but this question specifically is about the Index level;
You can currently index regular values (strings, numbers, dates, etc) and you can index an array which will more or less 'unroll' the array into separate index entries. However, what you are trying, indexing an object is not possible at this point. An object (like data) will be ignored if you try to index it.
Currently, you have two options:
as you mentioned, using Map/Get at query time.
listing all values of the data object in the index since you can select specific values of an object in the index (which is however less flexible if new attributes arrive later on in the object)
We intend to support indexing of objects in the future, I can't provide an ETA yet though. There is a feature request on our forums as well that you can vote up: https://forums.fauna.com/t/object-as-terms-instead-of-scalar-s/628
You're going to want to use the Select function on the Ref you get back from the Index if you only want the data field back.
For an individual document, you can do something like this
Select( "data",
Get(
Match(
Index("yourIndexName"),
**yourIndexTerm // Could point to String/Number/FQL Ref
)
)
)
For a list of documents, you can use Paginate as you said but you can still pull the data property out of each document
Map(
Paginate(
Match(
Index("yourIndexName"),
**yourIndexTerm // Could point to String/Number/FQL Ref
)
),
Lambda("doc", Select("data", Get(Var("doc"))))
)
Greetings StackOverflow!
Suppose I have an Elm app with a variable number of text input fields. I'd like to reflect the state of these input fields in the model.
Model and view are easy enough: View just has a Array String field in it somewhere.
The view is then computed simply by calling List.map (HTML input ...) on that list of strings.
However, I'm a bit lost how to do the update function and message type.
The message could be somethign like this:
type Msg = InputFieldUpdated Int String
Here, the Int refers to the position in the Array that the string to be updated has. However, if I do it this way, I can create messages that refer to non-existant array positions simply by setting the Int to something that is out of range.
For a fixed number of input elements, one can solve this problem very elegantly by simply using a union type with a different value for each input, but what about my situation? In the domain of "making impossible states impossible", is there some trick for that that I'm missing?
However, if I do it this way, I can create messages that refer to non-existant array positions simply by setting the Int to something that is out of range.
According to the documentation of Array.set, the array stays untouched if the index is out of range.
Please, have a look at this ellie-app example. It mostly models the problem, that you've described. Array of elements is rendered and the elements can be added dynamically:
view : Model -> Html Msg
view model =
div []
[ div [] (toList (Array.indexedMap viewElement model.elements))
, button [ onClick Add ] [ text "Add" ]
]
In order to update a particular element, you need to get it by index. Since the type of the result from Array.get is Maybe a, type system will force you to process all the cases (when the element exists and doesn't):
Increment index ->
case get index model.elements of
Just element ->
{ model | elements = set index (element + 1) model.elements }
Nothing ->
model
The example is just for demonstration purposes, if you don't need the current element, then Array.set function can be safely used.
I was wondering what kind of data I can use to handle a dataChanged-signal in a QML ListModel.
I found out that it has three arguments, two of which are QModelIndices and one is a QVariant(...).
So from the first two (which seems to be the same?) I can get the row, column (which is supposed to be 0), the model itself and uhm... stuff
But why do I get it twice?
And what is the content of the third? It is not null, but I haven't found a property I could use to retrieve some useful data from it.
A ListModel implementsQAbstractItemModel, the dataChanged signal you are seeing is the one defined in this class :
void QAbstractItemModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int> ())
The 2 first parameters tell us that all data between the first and second indexes are changed. The 3rd parameter is a list of roles where the data has changed, if the list is empty it means the data at all roles has potentially been changed.
In your case the first and second indexes are the same because only one row is changed at a time.
I'm writing a Less mixin.
I want to be able to pass the mixin several parameters. The first will be a string. The rest, an infinite number of parameters, will be value pairs.
In my mixin how can I loop through the infinite number of parameters?
For example one time I will call...
.my-mixin(#name, #foo: bar, #hello: world);
and another time...
.my-mixin(#name, #iam: cool, #youare: lame, #someoneis: awesome);
Here's what it would look like if Less supported JS/PHP...
.my-mixin() {
#name: #arguments[0]; //First param
for (#arguments as #label => #value) {
#label: #value;
}
}
Is this possible?
In fact you ask two questions. First how to create a mixin that can accept an endless number of parameters, and secondly who to iterate over the list / array of parameters.
Less has the special ... syntax to create mixins with an endless number of parameters. The official documentation can be found here: Advanced arguments and the #rest variable. An example / use case can be found at Can I define a LESS mixin to generate a transition-property with a variable number of parameters?.
The special ... syntax can be used to assign the parameter list to a variable by adding the variable name before the ...:
.mixin(#parameter1, #endlesslistofparameters...) {}
The #endlesslistofparameters variable now contains a list of parameters, you can use the Less list functions to extract a value from this list (or find its length):
length() returns the length of a list and extract(#list,position) return the value of a certain position in the list. Notice that the first value is on position 1 and not 0.
Finally you can use a loop to iterate over this list of arguments.
In Less a mixin can call itself. Such recursive mixins, when combined
with Guard Expressions and Pattern Matching, can be used to create
various iterative/loop structures.
See also: Loop over an array of name value pairs in LESS
All together i think you can write something like that shown below:
.my-mixin(#name,#properties...) {
.setproperties(#iterator:1) when (#iterator <= length(#properties)) {
#propertyname: extract(extract(#properties,#iterator),1);
#{propertyname}: extract(extract(#properties,#iterator),2);
.setproperties((#iterator + 1));
}
.#{name} {
.setproperties();
}
}
.my-mixin(jared; iam cool, youare lame, someoneis awesome);
The preceding Less code will compile into the following CSS code:
.jared {
iam: cool;
youare: lame;
someoneis: awesome;
}
And than also notice that Less allows you to Passing Rulesets to Mixins since version 1.7, which enables you to write:
.my-mixin2(#name,#properties) {
.#{name} {
#properties();
}
}
.my-mixin2(jared; {iam: cool; youare: lame; someoneis: awesome;});