<form class="col-xs-12"> <script type="text/javascript">
var stocks = {
"938975": true,
"938977": true,
"938979": true,
"938981": true,
"938983": true,
"938985": true,
"938987": false,
"938989": true,
"938991": true,
"938993": true,
"938995": true,
"938997": false,
"938999": true,
"939001": true,
"939003": true,
"939005": true,
"939007": true
};
How do I get and loop it, that if there is a true value in var stocks for any variable bot goes further but when there is false it stops?
For now I'm using something like that, hope you understand:
div = soup.find("form",("class"=="col-xs-12")).find("script",("type"=="text/javascript"
I’m doing bot in python
See if this can help!
Have added the code so if we have some entries at the end, even if we do not have false, they also get added. Its outside the loop and can be removed if not needed.
var stocks = {"938975":true,"938977":true,"938979":true,"938981":true,"938983":true,"938985":true,"938987":false,"938989":true,"938991":true,"938993":true,"938995":true,"938997":false,"938999":true,"939001":true,"939003":true,"939005":true,"939007":true};
var arraysOfStocks = [],tempArray = [];
for (let [key, value] of Object.entries(stocks)) {
//console.log(key +":"+value);
if(value){
tempArray.push(key);
} else {
arraysOfStocks.push(tempArray);
tempArray = [];
}
}
arraysOfStocks.push(tempArray);
tempArray = [];
console.log(arraysOfStocks);
Related
I'm using the EVERY method on a Select all feature in my project.
As an onChange listener on my checkboxes my function runs this code to see if the value of canWrite on each object is set to true/false
checkSelected() {
let testWrite = this.modalData.columnPermissions.every(function (item)
return item.canWrite;
});
this.isEveryWriteSelected = testWrite;
}
However, the scope of the model has changed to include an additional property "IDM=true/false"- IDM items cannot be selected so presently this listening code now never fires true.
I am trying to adapt my function to now only check canWrite=true if the item contains IDM=false
Am I able to use EVERY in this situation by ignoring item.IDM=false?
Have tried adding an if statement as a test, but this hasn't resolved my issue
let testWrite = this.modalData.columnPermissions.every(function (item) {
if (!item.IDM) {
return item.canWrite;
}
});
MY HTML - which is Angular 2 can be seen below:
This is the select all checkbox which is listening for isEveryWriteSelected
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="customCheck1c" [(ngModel)]="isEveryWriteSelected" name="isEveryWriteSelected" (change)="selectAll('Write', isEveryWriteSelected)" [disabled]="modalData.role != 1 || roleConfirm">
<label class="custom-control-label" for="customCheck1c"><span>Select All</span></label>
</div>
while each rendered checkbox has an on change event calling the above function
<div class="custom-control custom-checkbox" *ngIf="!column.IDM">
<input type="checkbox" class="custom-control-input" id="customCheck{{column.$id}}-write" name="customCheck{{column.$id}}-write" [(ngModel)]="column.canWrite" [checked]="column.canWrite" [disabled]="modalData.role != 1 || roleConfirm" (change)="checkSelected()">
<label class="custom-control-label" for="customCheck{{column.$id}}-write"><span class="hideMe"> </span></label>
</div>
filter out all items with IDM=true first and then run an every on the rest of the items.
This (in my opinion) will make your code more readable for the next developer.
const modalData = {
columnPermissions: [
{IDM: true, canWrite: true},
{IDM: false, canWrite: true},
{IDM: true, canWrite: true},
{IDM: false, canWrite: true},
{IDM: true, canWrite: true},
{IDM: false, canWrite: true},
{IDM: true, canWrite: true},
{IDM: false, canWrite: true},
{IDM: false, canWrite: true},
{IDM: true, canWrite: true},
]
}
const checkSelected = () => {
let testWrite = modalData.columnPermissions
.filter(({ IDM }) => !IDM)
.every(({ canWrite }) => !!canWrite)
console.log(testWrite)
}
checkSelected()
If I understand correctly, you need to check all items which have either canWrite true or IDM true
let testWrite = this.modalData.columnPermissions.every(function (item) {
return item.canWrite || item.IDM;
});
Since your final result is only based on items where IDM is false, you should first filter all items with such property. And then the original logic with every would work fine.
Example code:
return this.modalData.columnPermissions
.filter(function (item) {
return item.IDM === false;
})
.every(function (item) {
return item.canWrite;
});
You were close when you had this idea:
let testWrite = this.modalData.columnPermissions.every(function (item) {
if (!item.IDM) {
return item.canWrite;
}
});
All you have to do is return true in the else clause for items with IDM set to true:
let testWrite = this.modalData.columnPermissions.every(function (item) {
if (!item.IDM) {
return item.canWrite;
}
// else...
return true;
});
The reason for doing that is, by returning true, only the items with IDM set to false will be able to effect the final result and potentially turn it false by returning false in the predicate statement.
Hello everyone I am trying to write data to my firebase database. I have multiple "codes" that can be generated by the user and should be shown as seperate nodes inside a child node.
firebase.database().ref('users/').push({
user: uid,
titel: title,
codes: {
for(var i = 0;i < arrCodes.length;i++){
shareCode[i]: true,
}
},
enable: true,
});
the important part should look like this:
...
titel: title,
codes: {
xksodkcisd: true,
ksocjdiuvn: true,
// and so on
},
enable: true,
...
Move the loop outside the .push()?
var shareCodes = {};
for (var i = 0; i < arrCodes.length; i++) {
shareCodes[i] = true;
}
firebase.database().ref('users/').push({
user: uid,
titel: title,
codes: shareCodes,
enable: true,
});
I have a problem creating ng-grids dynamically:
The next function loops through each element of $scope.dataSparqlResponses (each element is an array of data) and put the value of the iteration in $scope.dataSparqlAux. And $scope.dataSparqlAux is the variable used in the grids (data input). The problem is that in each iteration this variable ($scope.dataSparqlAux) is reassigned, so in the template I can only see the last grid with data.
**controller.js**
$scope.crearGrids = function() {
angular.forEach($scope.dataSparqlResponses, function(elem) {
$scope.dataSparqlAux = elem.data;
$scope.dataGrids.push({grid: {
data: 'dataSparqlAux',
enablePinning: false,
showFooter: true,
selectedItems: [],
i18n: 'es',
showSelectionCheckbox: true,
afterSelectionChange: function() {
console.log(this);
},
columnDefs: [{field: elem.nombre + '.value', displayName: elem.nombre, cellTemplate: templateWithTooltip}]
}});
console.log($scope.dataGrids);
});
};
**template.html**
<div data-get-width data-num-elementos="{{dataGrids.length}}" >
<div ng-repeat="dataGrid in dataGrids">
<div class="tabla_det" ng-grid="dataGrid.grid"></div>
</div>
</div>
is possible to do something like this?
$scope.dataGrids.push({grid: {
**data: 'dataSparqlResponses[cont]',**
enablePinning: false,
showFooter: true,
selectedItems: [],
i18n: 'es',
showSelectionCheckbox: true,
afterSelectionChange: function() {
console.log(this);
},
columnDefs: [{field: elem.nombre + '.value', displayName: elem.nombre, cellTemplate: templateWithTooltip}]
}});
console.log($scope.dataGrids);
How can I fix this to create grids and display information dynamically?
Regards and thanks for your time.
EDIT: here a plunker with the problem http://plnkr.co/edit/zYtuMW4TKW053YoDY0kg?p=preview
I've shared an answer on github about your issue.
Basically, data is referencing a variable, you're not storing it.
What you can do is reference a new variable on every loop, as shown in the jsbin.
Declare an index :
var index = 0;
You declare your string with the index of the sub-document :
var dirtyConcat = 'dataSparqlResponses['+index+'].data';
Don't forget to increment the index :
++index;
Then, you reference it.
data: dirtyConcat,
I'm trying to send values of an array created by checkboxes to the constructor of a "buzz" sound object. Code Follows.
<input type="checkbox" name="loops" value="drums01" id="drums01" class="Checkbox" > Drums #1</li>
<li><input type="checkbox" name="loops" value="drums02" id="drums02" class="Checkbox"> Drums #2</li>
<li><input type="checkbox" name="loops" value="guitar01" id="guitar01" class="Checkbox"> Guitar #1</li>
//CHECKBOXES
<button class="button button_type_sound" id="b01">Play<q class="key" id="key_q">Q</q></button>
//BUTTON
var arr = new Array();
var drums01 = new buzz.sound("drumloop01", {
formats: [ "wav" ],
preload: true,
autoplay: false,
loop: true
});
var drums02 = new buzz.sound("drumloop02", {
formats: [ "wav" ],
preload: true,
autoplay: false,
loop: true
});
var guitar01 = new buzz.sound("guitarloop01", {
formats: [ "wav" ],
preload: true,
autoplay: false,
loop: true
});
//ATTEMPT TO CREATE SOUND OBJECT FROM ARRAY AND PLAY IT
$("#b01").click(function(event){
event.preventDefault();
var arr = new Array( $("input:checkbox:checked").map(function(){
return this.value;
}).toArray());
console.log(arr.toString());
console.log("Try Playing Sound");
console.log(arr.toString());
var myGroup = new buzz.group(arr.toString());
myGroup.play();
});
Console Gives me the following error:
drums01,drums02 index.html:68
Try Playing Sound index.html:71
drums01,drums02 index.html:72
Uncaught TypeError: Cannot call method 'apply' of undefined
Here is a working fiddle created fixing the code you posted in your question.
http://jsfiddle.net/fmKeV/3/
Explanation
As you may see, in the "init section" I create an object literal of instances of buzz.sound.
Then, in the event handler of the button I map every selected checkbox to the corresponding sound (I changed the value of the input elements so that it is the same as the key in the buzzSounds object).
The new Array in new Array($() ... .toArray()) in your code is not needed. The toArray() method called on the result of the map function is sufficient, otherwise the result would be a nested array, which is not what the buzz.group function needs.
Code
Markup
<ul class="sounds">
<li>
<input type="checkbox" name="loops" value="drumloop01" id="drums01" class="Checkbox" />Drums #1</li>
<li>
<input type="checkbox" name="loops" value="drumloop02" id="drums02" class="Checkbox" />Drums #2</li>
<li>
<input type="checkbox" name="loops" value="guitarloop01" id="guitar01" class="Checkbox" />Guitar #1</li>
</ul>
<button class="button button_type_sound" id="b01">Play
<q class="key" id="key_q">Q</q>
</button>
Javascript
$(document).ready(function() {
// init sounds
var buzzSounds = {};
buzzSounds.drumloop01 = new buzz.sound("drumloop01", {
formats: ["wav"],
preload: true,
autoplay: false,
loop: true
});
buzzSounds.drumloop02 = new buzz.sound("drumloop02", {
formats: ["wav"],
preload: true,
autoplay: false,
loop: true
});
buzzSounds.guitarloop01 = new buzz.sound("guitarloop01", {
formats: ["wav"],
preload: true,
autoplay: false,
loop: true
});
//CLICK EVENT HANDLER
$("#b01").on('click', function(e) {
var sounds, group;
//0) Prevent default
e.preventDefault();
//1) map every selected element to the sound defined in the "buzzSounds" object
toPlay = $(".sounds input:checkbox:checked").map(function() {
return buzzSounds[this.value];
}).toArray();
//2) create a group from the collected buzz.sound instances
myGroup = new buzz.group(toPlay);
//3) play the group
console.log("Try Playing Sounds", toPlay, myGroup);
try {
myGroup.play();
} catch (e) {
console.log('uh-oh', e);
//in this example the sound files have not been loaded, so an error could be raised
}
});
});
Try something like this:
$(document).ready(function () {
var drums01 = new buzz.sound("drumloop01", {
formats: ["wav"],
preload: true,
autoplay: false,
loop: true
});
var drums02 = new buzz.sound("drumloop02", {
formats: ["wav"],
preload: true,
autoplay: false,
loop: true
});
var guitar01 = new buzz.sound("guitarloop01", {
formats: ["wav"],
preload: true,
autoplay: false,
loop: true
});
//ATTEMPT TO CREATE SOUND OBJECT FROM ARRAY AND PLAY IT
$("#b01").click(function (event) {
event.preventDefault();
var arr = new Array();
$('input[type="checkbox"]').each(function () {
arr.push($(this).val());
});
console.log(arr.toString());
console.log("Try Playing Sound");
console.log(arr.toString());
var myGroup = new buzz.group(arr.toString());
myGroup.play();
});
});
Let me know how it works out.
fiddle
as far as I know, to create a buzz.group we should pass the array no the string:
Sounds can be added to a group by passing an array to the constructor.
but you pass string instead, so it should be like this:
var myGroup = new buzz.group([
mySound1,
mySound2,
mySound3
]);
I changes your fiddle example like this:
$(document).ready(function () {
var drums = {};
drums.drums01 = new buzz.sound("drumloop01", {
formats: ["wav"],
preload: true,
autoplay: false,
loop: true
});
drums.drums02 = new buzz.sound("drumloop02", {
formats: ["wav"],
preload: true,
autoplay: false,
loop: true
});
drums.guitar01 = new buzz.sound("guitarloop01", {
formats: ["wav"],
preload: true,
autoplay: false,
loop: true
});
$("#b01").click(function (event) {
event.preventDefault();
var arr = new Array();
$('input[type="checkbox"]:checked').each(function () {
arr.push(drums[$(this).val()]);
});
var myGroup = new buzz.group(arr.toString());
myGroup.play();
});
});
check the new DEMO out.
The Problem in you have in your code is, you are passing the variable names as a string array, whereas you should pass the actual objects. to solve your problem you should make them accessible using a accessible in the context object like var drums = {} which you can use it in your anonymous function.
for mor information check this link out.
here is the list: http://www.elizabethcastro.com/html/extras/entities.html
I either want to enable all of them, or disable all of them... (aside from < and > of course)
Is there a way to do this?
there is the config.entities_additional = "", but that is a comma separated list of all the entities you want to store.
preferably, I'd like to disable the entities entirely, but setting config.entities = false; doesn't do anything. o.o
#Cheery's answer solves the situation where the editor uses the config.js file.
however,
CKEDITOR.replace("selected_text_actual", {
uiColor: "#F5F5F5",
toolbar: "myToolbar",
scayt_autoStartup: false,
enterMode: CKEDITOR.ENTER_BR,
forcePasteAsPlainText: true,
forceSimpleAmpersand: true,
height: '170px',
entities: false,
basicEntities: false,
entities_greek: false,
entities_latin: false,
toolbarCanCollapse: false,
resize_enabled: false,
disableNativeSpellChecker: false,
removePlugins: 'elementspath',
editingBlock: false}).setData(text_for_editor);
Still has the HTML entities.
Set all of them to false:
config.entities = false;
config.basicEntities = false;
config.entities_greek = false;
config.entities_latin = false;