onEditCell issue with dhtmlxGrid - grid

I'm using dhtmlxGrid and as I've found in the docs (https://docs.dhtmlx.com/api__dhtmlxgrid_oneditcell_event.html) returning "true" confirms the edit, while a value (for example newValue) sets the value.
I've tried both methods, but neither of them works! I can't confirm the edit by "true" nor set the value by "newValue".
Here is my code:
myGrid.attachEvent("onEditCell", function(stage,rId,cInd,nValue,oValue){
doOnEdit(stage,rId,cInd,nValue,oValue)
});
...
function doOnEdit(stage,rId,cInd,nValue,oValue){
if (cInd==0 && nValue=="100")
return false
return true
}
Can anybody explain my mistake or is there a bug?

Please, try to use the following solution:
myGrid.attachEvent("onEditCell", doOnEdit);
...
function doOnEdit(stage,rId,cInd,nValue,oValue){
if (cInd==0 && nValue=="100")
return false
return true
}

Related

Shortest way to specify a return value expectation for a specific argument in Mockery

I want to create a Mock with a method that should return true for a specific argument, and false for any other argument.
I can achieve this with:
$this->myMock = Mockery::mock(MyClass::class);
$this->myMock->shouldReceive('myMethod')->with('my-argument')->andReturn(true);
$this->myMock->shouldReceive('myMethod')->andReturn(false);
But I was wondering if there's any shorter way to specify this, as I have to do this for many mocks, and looks like a lot of code for this simple purpose (note my properties/classes/methods/arguments names are quite longer than this example).
You can use Mockery's andReturnUsing-method. It takes a closure to calculate the return value by evaluating the provided argument. Should work like:
$this->mock
->shouldReceive('myMethod')
->andReturnUsing(function ($argument) {
if ($argument) {
return true;
}
return false;
});
I discovered I can use:
$this->myMock = Mockery::mock(MyClass::class);
$this->myMock->shouldReceive('myMethod')->passthru();
This will defer the calls to myMethod() to the real object, which will return true or false depending on the argument - this obviously doesn't do the same thing the code in the question does, but it does work in my scenario and it's quite shorter.

.numChildren() always returning 0

I was following the likes example
using their exact structure, but for a different purpose:
/functions-project-12345
/db
/1
contacts_count: 0
/contacts
1: true
2: true
3: true
contacts_count gets created at the correct location, Although for some reason, contacts_count keeps returning 0
exports.contactsCount = functions.database.ref('/db/{userid}/contacts').onWrite(event => {
return event.data.ref.parent.child('contacts_count').set(event.data.numChildren());
});
I have also tried setting the trigger at /db/{userid}/contacts/{id}, and after reading all the docs, still I can't seem to get it to return the correct count.
in fact, having the exact same structure as in the likes example:
/functions-project-12345
/posts
/key-123456
likes_count: 32
/likes
user123456: true
user456789: true
user786245: true
and running on the server:
exports.countlikes = functions.database.ref('/posts/{postid}/likes').onWrite(event => {
return event.data.ref.parent.child('likes_count').set(event.data.numChildren());
});
still saves 0 into likes_count
is event.data in event.data.numChildren() a reference to the /db/{userid}/contacts node, right ?
UPDATE 04/13/17: The solution below only works if you can guarantee children nodes are only added (not deleted or changed) and does not handle the count node being deleted. For a more robust solution, check out the updated child count example in the firebase/functions-samples repo.
I'm not sure exactly what is going wrong with your code (I just tested the example and it works for me), but a safer way to do this same thing is to use transaction() instead of set(). Modifying your provided sample code, that would look like this:
exports. contactsCount = functions.database.ref('/db/{userid}/contacts')
.onWrite(event => {
var contactCountRef = event.data.ref.parent.child('contacts_count');
return contactCountRef.transaction(function(currentCount) {
return (currentCount || 0) + 1;
});
});
This code should work for you since it doesn't rely on whatever issue you are running into with numChildren() and it has the added benefit of being safe from race conditions that are present in the official sample. We are actually working to get the sample updated to properly use a transaction instead.

How do I determine, if Observable has never received anything?

How do I determine, if the Observable is "empty"?
Better, that it has never received anything.
My code looks like this:
spots: Observable<Spot[]>;
And I've tried several things I found on Google like:
spots.isEmpty();
spots.length;
spots.length();
spots().length;
spots.first();
But none of them works like I want..
I need this functionality, to fill a list in Ionic2 with No items found until the first item is loaded.
This is how I solve it in my code:
if ( arrayOfItems && arrayOfItems.length > 0 ) {
// display the list
return arrayOfItems.map((item) => { return item; })
} else {
// show a message that nothing was found
return "Nothing to see here...";
}
This will check that the variable has some sort of positive value (ie. it is not null, false or undefined) and that the array has at least one value. If that is not the case then display a message that nothing was found.
I solved it like this:
I have an variable let isEmpty=true; and set it to false when I receive the first Object in the Observable:
spots.subscribe(() => {
this.empty = false;
...
});

How to read in a Bit field to create a checkbox

I have a field in my SQL database that is a BIT field.
I want to read in that field. If 1 then checkbox is true, else false.
I started off with this code, but getting error. Any advice on how to do this?
If (MyReader["TArchive"] == 1) then
Regards
Tea
Try this:
myCheckbox.Checked = Convert.ToBoolean(MyReader["TArchive"]);
Try this
If (MyReader.GetBoolean("TArchive")) // returns true if value is 1
{
// checkbox true
}
else
{
// checkbox false
}
Not tested but GetBoolean does this automatically.

Does Adobe Flex SDK contain a helper function for converting strings to Booleans?

Yes, it is a trivial question. I was just wondering. Does the framework have a helper function that does something like this:
switch (value)
{
case "true":
return true;
case "false":
return false;
default:
return Boolean(value);
}
No. See this Stackoverflow post.

Resources