RxList<String> selectedMemberList = <String>[].obs;
selectedMemberList = [180,160,150]
I want to display text in red color if ID contains in selectedMemberList.
So, I simply called,
if selectedMemberList.contains('180'){
text in red color
}else{
text in black color}
but, I got text in black color every time. That means ID doesnt matched.
How do I match member ID to given selectedMemberList.
if your items are in a single string separated by a comma, first convert that into a list like this :
String collectedIds = "180,160,150";
final split = tagName.split(',');
final Map<int, String> selectedMemberList= {
for (int i = 0; i < split.length; i++)
i: split[i]
};
and now you can check the condition :
if selectedMemberList.contains('180'){
text in red color
}else{
text in black color}
Hope this will help you.
Here is a cleaner way on checking if value exist on a list.
RxList<String> selectedMemberList = <String>[].obs;
selectedMemberList = ["160","180","150"];
if (selectedMemberList.where((item) => item == "180").isNotEmpty){
text in red color
} else {
text in black color
}
Related
I have 2 massive sheets (over 100 columns, 400+ rows). I'm trying to highlight currently changed cells in yellow. But, also removing any previous yellow highlights first. (there are other cells with different colors that need to be left alone).
Prior to running this code I am saving a copy of sSheet each week and comparing sSheet with the copy from the previous week "changesSheet".
The changesSheet is a comparison sheet full of formulas comparing last week's data with current data. It is mostly blank, but the adjusted cells have data...the rest of the cells are blank.
The cells in both changesSheet and sSheet are aligned. Meaning if there was a change in cell 'A10' of sSheet it is reflected in 'A10' of changesSheet.
for each cell,
if its yellow on sSheets, change sSheets cell to white
if it has data on changesSheet, change sSheet cell to yellow
The code below works.... But it's way too slow and will never make it through 400 rows without timing out.
var sSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Requests Form');
var changesSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('ChangesSheet');
for (row=1;row<lastRow+1;row++){
Logger.log(row);
for(col=1;col<lastCol+1;col++){
var cell = sSheet.getRange(row,col);
var cell2 = changesSheet.getRange(row,col);
if(cell.getBackground()== "#ffff00"){
cell.setBackground('white');
}
if (cell2.getValues()!=""){
cell.setBackground('yellow');
}
}
}
Any suggestions to make this go faster?
I believe your goal is as follows.
You want to reduce the process cost of your script.
About if it has data on changesSheet, change sSheet cell to yellow, in your script, the cell values are not checked. So, I guess that you might be using conditional formatting rules. If my understanding is correct, how about the following modification?
Modified script:
var sSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Requests Form');
var changesSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('ChangesSheet');
var backgrounds = changesSheet.getDataRange().getBackgrounds();
var values = backgrounds.map(r => r.map(c => c == "#ffff00" ? "yellow" : "white"));
sSheet.getRange(1, 1, values.length, values[0].length).setBackgrounds(values);
By this modification, I thought that the process cost might be able to be reduced a little.
In this modification, when the background color of cells in "ChangesSheet" sheet is "#ffff00", the same cell coordinate is changed to "yellow" in "Requests Form" sheet.
If you want to reverse this, please modify c == "#ffff00" ? "yellow" : "white" to c == "#ffff00" ? "white": "yellow".
References:
getBackgrounds()
setBackgrounds(color)
Added 1:
From your following reply,
if (cell2.getValues()!=""){ I only need to check that there IS some data in the same cell on the changesSheet. Currently there is no conditional formatting on the changesSheet
From your showing script, I thought that you might be using conditional formatting roles. But, if you want to check only whether the cell is empty, I thought that the following sample script can be also used.
var sSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Requests Form');
var changesSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('ChangesSheet');
var backgrounds = changesSheet.getDataRange().getDisplayValues();
var values = backgrounds.map(r => r.map(c => c ? "yellow" : "white"));
sSheet.getRange(1, 1, values.length, values[0].length).setBackgrounds(values);
In this case, it checks whether the cells are empty instead of the background colors.
Added 2:
About your following additional request,
The script changes ALL cells white or yellow. There are already cells with different colors on the sSheet. If a cell is not yellow, can it use the original sSheet color?
In this case, how about the following sample script?
var sSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Requests Form');
var changesSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('ChangesSheet');
var backgrounds = changesSheet.getDataRange().getDisplayValues();
var t = sSheet.getDataRange().getBackgrounds();
var values = backgrounds.map((r, i) => r.map((c, j) => c ? "yellow" : t[i] && t[i][j] ? t[i][j] : null));
sSheet.getRange(1, 1, values.length, values[0].length).setBackgrounds(values);
I want to create a drop down like this:
.
I have an string array as datasource of an drop down menu.I want to give background to element at 3rd index of an array.
I have tried it in doing all things possible but not able to find out any solution.
If you insert your values to list of UIButtons (let btns : [UIButton] = [btn0, btn1, btn2, btn3]), you can do that:
for i in 0..<btns.count {
if i == 2 {
btns[i].backgroundColor = .red
}
}
or just find needed UI-element and set needed color.
You need to create an array of similar size as your dataSource and this is only if you can't add a property of the color
var arr = [UIColor]()
arr = [.red,.green,.blue]
arr[2] = .orange
Hello I apologize in advance for my question which I'm sure is pretty basic.
On a map are set 33 landmarks with an array calling a class in the library.
A second array defines the coordinates of those landmarks.
for (var i:uint = 0; i < 33; i++) {
mark[i] = new landMark();
landMarks.addChild(mark[i]);
mark[i].x = lmxy[i]['x'];
mark[i].y = lmxy[i]['y'];
}
var lmxy:Array = [{x:1620,y:880},{x:1850, y:1050},etc...];
So far so good, the landmarks show each in its right place.
The third array contains different legends supposed to show when a landmark is clicked.
So the landmark [1] should show the legend [1] and the landmark [31] the legend [31]
var lgd:Array = [lgdA, lgdB, etc... ];
var legends:MovieClip;
for (var j:uint=0;j<lgd.length;j++) {
legends = new lgd[j]();
legends.x = 300;legends.y = 170;
}
Edit cause obviously that was unclear :
I tried that in the loop to link the marks to the legends but I get an error :
mark[i].addEventListener(MouseEvent.CLICK, getLgd);
function getLgd(e:Event):void {stage.addChild (lgd[i]);}
Any help would be very welcome !
The problem is that the variable i doesn't have a definition. The only way for you to find out which of the landmarks were clicked is to find its index in the array, then you can add the legend that has the same index. Because the index isn't passed from the event listener, you need to use e which has the target property.
This should do the trick:
mark[i].addEventListener(MouseEvent.CLICK, getLgd);
function getLgd(e:Event):void
{
var i:int = mark.indexOf(e.target);
stage.addChild(lgd[i]);
}
recently stakantin ( https://stackoverflow.com/users/1875610/stakantin ) helped me with a question that I have made about change the text of a label with this code:
$label=$this->add('View_HtmlElement')->setElement('h4')->set('Test');
$f=$this->add('Form');
$f->addField('Checkbox','click')->js('click',$label->js()->text('hallo world'));
I'm trying to do this (I cannot figure out how to do it):
I have a label "$label=$this->add('View_HtmlElement')->setElement('h4')->set('100');"
and I have some fields of a form with check boxes. Each check box has a number.
Is it possible when the checkbox is clicked to do operations on that label ?
example:
Label: 100
field1 100 checkbox
field2 200 checkbox
If I click checkbox of field1, then label value is 200 (its original value plus 100 of field1), and so on...
I don't know if I'm very clear buy thanks for any help.
Alejandro
Example:
$f = $this->add('Form');
$l1 = $f->addField('Line','l1')->set(100);
$cb1 = $f->addField('Checkbox','cb1','100');
$l2 = $f->addField('Line','l2')->set(300);
$cb2 = $f->addField('Checkbox','cb2','300');
$cb1->js('change','
if (this.checked) {
$(this).parent().find("label")
.text(parseInt(100) + parseInt('.$l1->js()->val().'));
} else {
$(this).parent().find("label").text(100);
}
');
$cb2->js('change','
if (this.checked) {
$(this).parent().find("label")
.text(parseInt(300) + parseInt('.$l2->js()->val().'));
} else {
$(this).parent().find("label").text("300");
}
');
But but this is not very good way to add javascript. Creating of js function based on my example in .js file is much clearer way.
I want...
I am trying to do a loop like this
my-red = #fcc
my-blue = #ccf
for color in my-red, my-blue
.{color}
color x
I want it to output
.my-blue {
color: #ccf;
}
.my-red {
color: #fcc;
}
I can't seem to get both the variable name, and value as required
I have tried...
my-blue = #ccf
my-red = #fcc
for x in 'my-blue' my-red
.{x}
color x
But I just get either the class name or color name (depending on if I use a string as the variable name to iterate)
.my-blue {
color: "my-blue";
}
. {
color: #fcc;
}
You can use array for such task, so you can do this:
my-colors = my-red #fcc,
my-blue #ccf
for pair in my-colors
.{pair[0]}
color pair[1]
Doing so you declare the my-colors array and then iterate through it, using the first elements in the pairs as the names and second as the value.