I've been having trouble figuring out how to have multiple intervals used on a page. Normally, this wouldn't be a problem but I'm working to create a dynamic countdown script which uses data submitted by the user and have to abide by a few rules:
I need the interval only to clear specifically for given element.
I only need the interval to clear if there currently is an interval set in that specific element.
My idea was to count each interval and assign the number instance to each one. So something like this :
function(element, data, api) {
let intervalIds = [];
for (var i=0; i < intervalIds.length; i++){
}
intervalIds.push(setInterval(function(){
console.log(intervalIds[i]);
clearInterval(intervalIds[i]-1);
//timecalculations after
}, 1000 ));
}
This worked at first, however when I refresh the page with multiple intervals, but after I refresh the page there is only one interval.
If the element ID is the same and a interval has been set for this element then clear the previous interval
If the element ID is different just simply start a new interval
P.S with the software I'm using I can access the element id using data.elementId. ex: if (data.elementId == data.elementId) { do stuff }
I found out the answer to this riddle.
You would need to create a dynamic variable. To do this you would either need to use eval() or assign the variable to the window scope. Then assign the interval to that variable.
Luckily, the software I work with assigns a unique Id to each element added to the page. So I can use this unique Id to assign it to the variable to create the dynamic va
For example:
//unique id
var dynamicIntervalID = $(element).attr('id');
//clear interval if one exists
if (window["intervalIds"+dynamicIntervalID])clearInterval(window["intervalIds"+dynamicIntervalID])
//assign unique element id to interval
window["intervalIds"+dynamicIntervalID] = setInterval(function(){
...code here..
}, 1000 );
Hope this helps.
Related
I want to find the index my agent has in its population (named dullieses), which lives in my Main-agent.
I want to find one of my dullieses-agent via one of its variables (DullyID) which, in this example, shall be equal to my counter variable. Both are of type int.
I have tried the following to no avail:
int i = 0;
for ( i = 0; i < dullieses.size(); i++){
if (Main.dullieses(i).DullyID == counter){
traceln("I found myself! I have the index " + i);
break;
}
}
Error code: Cannot make a static reference to the non-static method dullies(int) from type Main.
How can I find my agent in my population and find its index?
I think you're probably already in main and don't need to add Main..
Anyway, I would recommend using:
Dully d = findFirst( dullieses, d -> d.ID == counter );
d.variable = 10;
I used variable and 10 as random examples, but this should give you the idea. Also replace Dully with whatever your agent type name is.
You don't need to use a custom ID parameter in your agents (at least not for what you're doing here).
All agents in a population have the getIndex function which returns their index in the population. Just be wary that, if you remove agents from a population, their indices will change (so you can't, for example, use their index as a unique ID for them in that case).
I am trying to mimic the functionality of the right sidebar of this example for my Angular site.
I don't know what this is called, or even how to go about it on the front end or back end!
My assumption:
Create a form with values coming straight from the DB and only show the desired parameter (i.e. db.collection.find(query, {parameter: 1}) which will be called to update each time a user modifies the form. Additionally, the results would also be updated on selection (I have over 100MB of documents, returning ALL of them would be troublesome, how can I limit the number of documents returned to let's say 20 or 50 (user input?) and paginate it (1000 documents returned / 50 per page = 20 'pages')
Each input that is selected, a { 'field' : value } would be returned -- but I am not sure how to control an empty value (i.e. what if a user doesn't pick a fuel type or transmission range?)
How do I go about designing such a feature correctly?
1) In your query, use limit statement:
var options = { "limit": 20 }
collection.find({}, options).toArray(...);
2) you can validate user empty input (for eg. with express-validator):
req.checkBody('postparam', 'Invalid postparam').notEmpty()
req.getValidationResult().then(function(result) {
if (!result.isEmpty()) {
res.status(400).send('There have been validation errors: ' + util.inspect(result.array()));
return;
}
and based on result choose default value/pass error/render ask page for user
I have comp_value that gets values between 1 .. 100.
In addition I have an input variable period (of the same range). I need to cover 2 ranges of comp_values: [1..period] and [period+1 .. 100]. Something like this:
cover some_event_e is {
item period using no_collect;
item comp_val using no_collect,
ranges = {
range([1..period], "Smaller_than_period");
range([period+1..100], "Bigger_than_period");
};
};
(The code causes compilation error since no variable can be written inside range).
Is there a way to collect the coverage?
Thank you for your help.
Ranges must be constant.
But if I understood your intent correctly, you can define new items like
cover some_event_e is {
item smaller_or_equal_than_period: bool = (comp_val in [1..period]) using
ignore = (not smaller_or_equal_than_period);
item greater_than_period: bool = (comp_val in [(min(100,period+1)..100]) using
ignore = (not greater_than_period);
};
Assuming period is always in [1..100].
I've got a form done in x++ (formBuild) and I managed to display different grids in different tabs. However, when I do a right-click record info on any of the grids other than the first one, the details are that of the first grid. Eg. The second row of grid 2 when I do a record info is actually the second row of grid 1.
One thing is all the grids are actually using the same table, just having different query ranges for each.
Any way to fix this?
Added code snippets
Making the grid:
for (counter = 0; counter < locations.lastIndex(); counter++)
{
formBuildDatasource = form.addDataSource(tableStr(SomeTable));
formBuildTabPageControl = formBuildTabControl.addControl(FormControlType::TabPage, locations.value(counter+1));
formBuildTabPageControl.caption(locations.value(counter+1));
formBuildGridControl = formBuildTabPageControl.addControl(FormControlType::Grid, locations.value(counter+1));
formBuildGridControl.allowEdit(0);
formBuildGridControl.dataSource(formBuildDatasource);
formBuildGridControl.height(500,-1);
formBuildGridControl.width(550,-1);
formBuildGridControl.addDataField(formBuildDatasource.id(), fieldNum(SomeTable, MachineId));
formBuildGridControl.addDataField(formBuildDatasource.id(), fieldNum(SomeTable, MachineStatus));
}
Adding the query:
for (counter = 0; counter < locations.lastIndex(); counter++)
{
fds = formRun.dataSource(counter+1);
qbds = fds.query().dataSourceNo(1);
qbr = Qbds.addRange(fieldnum(SomeTable, MachineLocation));
qbr.value(locations.value(counter+1));
}
This answer to your prior question applies here as well:
Adding view/temporary table records to Form Grid
You will have to use more than one datasource (using the same table). Remember to change the datasource attribute of the grids to match the correct one. My guess would be that they currently all reference the same datasource.
Can you make a query + view of the table, and have that as the 'child' entity?
I don't know why you can't have the same table referenced twice in the same form data sources, however. Ensure that the link between the tables are defined correctly, and you have no confusion with the datasource names that you use for them.
You actually need to set the datasource on the grid object using the id() method on the FormDataSource object, not just the full object.
Change from:
formBuildGridControl.dataSource(formBuildDatasource);
to:
formBuildGridControl.dataSource(formBuildDatasource.id());
Friends,
I have written the following JavaScript to ascertain which row of an tabular form the user is currently on. i.e. they have clicked a select list on row 4. I need the row number to then get the correct value of a field on this same row which I can then perform some further processing on.
What this JavaScript does is get the id of the triggering item, e.g. f02_0004 This tells me that the select list in column 2 of row 4 has been selected. So my Javascript gets just the row information i.e. 0004 and then uses that to reference another field in this row and at the moment just output the value to show I have the correct value.
<script language="JavaScript" type="text/javascript">
function cascade(pThis){
var row = getTheCurrentRow(pThis.id);
var nameAndRow = "f03_" + row;
var costCentre = $x(nameAndRow).value;
alert("the cost centre id is " + costCentre);
}
// the triggerItem has the name fxx_yyyy where xx is the column number and
// yyyy is the row. This function just returns yyyyy
function getTheCurrentRow(triggerItem){
var theRow = triggerItem.slice(4);
return theRow;
}
Whilst this works I can't help feeling that I must be re-inventing the wheel and that
either, there are built-in's that I can use or if not there maybe a "better" way?
In case of need I'm using Apex 4.0
Thanks in advance for any you can provide.
Well, what you have described is exactly what I typically do myself!
An alternative in Apex 4.0 would be to use jQuery to navigate the DOM something like this:
var costCentre = $(pThis).parents('tr').find('input[name="f03"]')[0].value;
I have tested this and it works OK in my test form.