Repeat the columns using data-sly-repeat based on the number entered in the cq dialog. Columns are not repeating - aem

I want to repeat the parsys in the columns based on the number of columns added in cq dialog. I can only get one column and the numbers of columns as entered
<div class="items">
<div data-sly-repeat="${grid.cols}" class="col col-lg-4 col-md-2 pt-2 pb-2">
<div data-sly-resource="${'content-{0}' # format=[colList.index], resourceType='wcm/foundation/components/parsys'}"></div>
</div>
</div>
</div>
carousel.js:
"use strict";
use(function() {
var properties = granite.properties,
colCount = properties.numberofcolumns ? properties.numberofcolumns : 3,
cols = '';
return {
"cols" : colCount
};
});

data-sly-repeat expects a list, not a number. You're only returning the number of columns. If you return an n-element list, data-sly-repeat will render an element for each item in the list.
It's a bit of a hack but in your carousel.js, you'd have to return an array with a list of values. The primary use case of data-sly-repeat (and data-sly-list) is to iterate over the elements of a collection returned by the underlying Java/JS code and output the properties of each item in the list. In your case, the only difference between the repeated div elements is the index.
use(function() {
var properties = granite.properties,
colCount = properties.numberofcolumns ? properties.numberofcolumns : 3;
var resultList = [];
for (var i = 0 ; i < colCount ; i++) {
resultList.push(i);
}
return {
"cols" : resultList // data-sly-repeat expects a collection
};
});
On a more general note, it seems what you're aiming to do is to include a bunch of paragraph systems by name to achieve some sort of column layout. Before attempting this, I would consider using the OOTB Layout Container component, which can be resized in Edit mode to fit any number of columns without any new development.

Related

ionic 3 input data binding is updating the different arrays of same type

I have a problem in input data-binding for one of our ionic 3 application. Whenever input changes which is changing the array values of different arrays of same type.
Here is my HTML
<ion-list>
<ion-item-sliding *ngFor="let item of storageItem ; index as i">
<div class ="itemList">
<input type="number" [value] ="item.storageOrderQuantity" (blur)="updateInputItemValue(item)"
[(ngModel)]="item.storageOrderQuantity" />
</div>
</ion-item-sliding>
</ion-list>
When ever input value changes, it is updating 'storageItem' array along with other arrays which has the same object(there are some other arrays 'item').
Here is my arrays declaration. Item is a model class.
item: Item[];
storageItem: Item[] = [];
storageItem' is a subset of 'item
Can anybody tell what would be the mistake in data-biding?
You have mentioned that storageItem is a subset of item
You probably already know this, Arrays and Object use concept of assign-by-reference. If you don't know this then read below article on Medium.
https://medium.com/#naveenkarippai/learning-how-references-work-in-javascript-a066a4e15600
So if you have the same object in both the arrays then updating one array will update the another,
const obj = { name : 'value' };
const arr1 = [1,2,3,obj];
const arr2 = [4,5,6,obj];
obj.name = 'yash'; // both arrays will have updated object
Now if you want to avoid this, then you can create a copy of the object before using it in another array.
Take reference from https://flaviocopes.com/how-to-clone-javascript-object/
item: Item[] = [
{ id : 'item1', list : [] },
{ id : 'item2', list : [] },
{ id : 'storageItem', list : [...storageItem] }
];
storageItem: Item[] = [list of storage items];
Now storageItem and item > id='storageItem' point to different arrays.
So your template will only update the storageItem now.

How to get count from repeater inside repeater in protractor?

I want to count the repeater that is nested into another repeater in protractor
var t2 = element.all(by.css('.footable.table.table-stripped.default.footable-loaded > tbody tr')).each(function(element, index){
element.all(by.repeater("el in punchApproval| filter : filterEmpSearch | orderBy:'Emp_Code' track by $index ")).each(function(element, text){
element.all(by.repeater("yl in el.PunchReq_sub")).count().then(function(cnt){
console.log("Count rw:" +index +"rw desc"+text+"count"+cnt) ;
});
});
Store the list identified by the repeater attribute.It must have a unique name then
print it using console.log(list) .where list contains the elements in the repeater you're having .
let list = element.all(by.repeater('.items li'));

Get Selected Value from Drop-Down Inside sap.ui.table.Table

I have created a table with a drop-down control (sap.m.ComboBox). I am adding rows dynamically using JSONModel. Here is the logic to bind my table:
My Table bind logic.
Now, I am trying to get values from the table:
var oTable = this.getView().byId("mytable");
var data = oTable.getModel();
var len = oTable._iBindingLength; // Get total Line Items in table
for (var i = 0; i < len; i++) {
var _val1 = data.oData[i].item1;
var _val2 = data.oData[i].item2;
// my value logic here
}
But this is bringing all the values instead of just selected value from my drop-down control.
If you want to get selected key from the ComboBox (drop-down), bind the appropriate model data to its property selectedKey. Once the user selects something, the selected key will be stored in the model thanks to the two-way data binding.
<m:ComboBox width="100%"
selectedKey="{foo/selectedKey}"
items="{
path: 'foo/items',
templateShareable: false
}"
>
<core:Item key="{key}" text="{text}"/>
</m:ComboBox>
I've updated my example from your previous question: https://plnkr.co/edit/8YvXxk?p=preview
The model data is automatically updated when the user selects something from the drop-down:

How to get values from input in sap.ui.table.Table?

In sap.ui.table.Table I have input field in one column. It will get nearly 300 records of data from back-end and binded in other columns.
User manually enters in the input field. Further, when he clicks on submit button I have to take all values from all input as array. Please give suggestions.
You can do it using data binding of table, as invoking getRows() on Table control to access Input fields of each row would not help in this case;it only returns only currently visible rows and you have around 300 records to access.
Here is the solution:
Get all data from back-end in JSONModel.
Add one property say inputValue to each item in model's data by iterating over it.
Bind this model to table and use inputValue property in table's template to bind column containing Input fields.
As JSONModel supports two-way binding, all the values which user has entered in an Input fields are available in your model.
And, lastly iterate over model's data to get inputValue for each row.
Above steps in action:
Step 1 and 2:
setModelForTable: function() {
var oModel = sap.ui.model.json.JSONModel( < URLToLoadJSON > );
var length = oModel.getData().results.length;
for (var i = 0; i < length; i++) {
var path = "/results/" + i + "/inputValue";
oModel.setProperty(path, "");
}
}
Step 3:
Now, that you have model with inputValue property in all the items of data, set the model on table; which will show all the Input fields in columns empty initially and will update the corresponding model entry as user modifies it.
<t:Column>
<t:label>
<Text text="User Input" />
</t:label>
<t:template>
<Input value="{inputValue}" />
</t:template>
</t:Column>
Finally, get all entered values in array.
var length = oModel.getData().results.length;
var aInputvalues = []
for (var i = 0; i < length; i++) {
var path = "/results/" + i + "/inputValue";
aInputvalues.push(oModel.getProperty(path));
}
I had the case which is a bit similar and I did it in the following way. Will work if you really do not need records which are not changed.
have a variable to store [] of changed records
Attach change to input field
on change push changed record to a variable
var source = event.getSource();
source.getModel().getProperty(source.getBindingContext().getPath());
or the value of the input field.
event.getSource().getValue();
In case you have a record Id you can just push this ID and input value.
4. on submit iterate through an []

Select/Get html node from an element using D3

Let's say I have an html object called element that I create using bellow code:
var xmlString = "<div class="parent"><span class="child"></span></div>"
parser = new DOMParser()
var element = parser.parseFromString(xmlString, "text/xml");
// or simply using jquery
var string = "<div class="parent"><span class="child"></span></div>"
var element = $(string);
What I want to do is to select span.child from element using D3, not from the document. Using d3.select('span.child') will try to look for the <span class="child"></span> in the html document.
I checked the documentation and it says:
A selection is an array of elements pulled from the current document.
But I want to select not from the document but from the above element that I just created. Is there any way?
After a bit of debugging I found out that if element is a object, not string, then d3.select(element) will not look for the element in the document instead it will return the element itself.
for detailed info:
d3.select = function(node) {
var group = [ typeof node === "string" ? d3_select(node, d3_document) : node ];
group.parentNode = d3_documentElement;
return d3_selection([ group ]);
};