One one side I have a generic viewModel class with a property named Value. As this class can be use in different cases, the type of Value is Object.
On the other side I have a list control with an ObservableCollection property named Items.
Is it possible to create a binding between Value and Items?
First I tried to bind them directly, but Items setter is never called
this.SetBinding (
() => Data.Value,
() => Items
);
Then I tried casting the Object property, Items setter is now called but the changes are never applied back to Data.Value
this.SetBinding (
() => Data.Value)
.WhenSourceChanges (
() => Items = Data.Value as ObservableCollection<double> )
Related
This question already has answers here:
mongoose .find() method returns object with unwanted properties
(5 answers)
Closed 5 years ago.
Working with a strange problem here. This is an array of objects which is pulled from mongodb and passed into the following function.
I tried the following 3 logs sequentially within the forEach on the array pulled from the database:
e (the object element within the array) which returns correctly. as you can see all the properties (keys) exist:
{ paid: false,
hotelWebsite: 'www.testing.com',
_id:5951848a24bb261eed09d638,
hotelAddress: '123 easy street',
...etc }
console.log(Object.keys(e)) is returning things that are not the keys...
[ '__parentArray',
'__parent',
'__index',
'$__',
'isNew',
'errors',
'_doc',
'$init' ]
and finally:
for(key in e){
console.log(key);
}
which returns an absolute mess of data, part of which DOES contain the actual keys of the object:
__parentArray
__parent
__index
$__
isNew
errors
_doc
$init
id
_id
hotelWebsite
hotelAddress
hotelNumber
hotelName
courseCost
courseDate
courseState
courseCity
courseName
paid
studentComments
studentEmail
studentPhone
studentCountry
studentZip
studentState
studentCity
studentAddress
studentCompany
studentName
schema
constructor
$__original_remove
remove
_pres
_posts
$__original_validate
validate
toBSON
markModified
populate
save
update
inspect
invalidate
$markValid
$isValid
ownerDocument
$__fullPath
parent
parentArray
on
once
emit
listeners
removeListener
setMaxListeners
removeAllListeners
addListener
$__buildDoc
init
$hook
$pre
$post
removePre
removePost
_lazySetupHooks
set
$__shouldModify
$__set
getValue
setValue
get
$__path
unmarkModified
$ignore
modifiedPaths
isModified
$isDefault
isDirectModified
isInit
isSelected
isDirectSelected
$__validate
validateSync
$__reset
$__dirty
$__setSchema
$__getArrayPathsToValidate
$__getAllSubdocs
$__handleReject
$toObject
toObject
toJSON
toString
equals
execPopulate
populated
depopulate
And a relevant sample of the code if needed:
studentsArray.forEach( (e, i) => {
if(task === 'nameTag'){
console.log(e);
console.log(Object.keys(e));
for(k in e){
console.log(k);
}
}
....
I need access to the properties (keys) for further processing within the forEach function. I am very confused on what is causing this and have never run into this sort of issue before. For the record the objects exist, using a console.log(typeof e) it IS an object (not a data "string"). I can access the properties using the dot or bracket notation but NOT using Object.keys() or for (keys in obj).
Can anyone help me sort this out please?
for ... in iterates all enumerable properties, both own and inherited. This is not "a strange bug," this is in fact the intended behavior.
As for the Object.keys(), unless it was overwritten by a non-compliant implementation, those are in fact enumerable keys of the object itself, so you are most likely mistaken. The e object has a .toJSON() method in its prototype that is implicitly called when you do console.log(e), so that is probably the output you are seeing there, and is not likely going to reflect exactly the same property keys as the original object. Try calling console.log(e.toJSON()) and I'm guessing it will be the same output as in the first one.
If you want only the object's own properties, use Object.getOwnPropertyNames(e).
If you want the keys printed in the first output, then use Object.keys(e.toJSON()).
I have a class instance (in my case the class is URL), called req_url. URL has a property that has a setter for one of its properties (search) that is implemented in a way that is problematic for me (doesn't just set the given value but does something to it first).
How can I override that setter without creating a class that inherits from URL (and then create a different setter)?
defineProperty doesn't work since it works at the Object level. I want to to do it on that specific type level.
Whenever you have an instance whose setter you want to bypass, calling Object.defineProperty on the instance to set the property does work:
class Foo {
set prop(arg) {
console.log('setter invoked');
}
}
const f = new Foo();
Object.defineProperty(f, 'prop', { value: 'val' });
console.log(f.prop);
It won't affect any object, it'll only affect objects you explicitly call Object.defineProperty with. The collisions with other objects you seem to be worried about won't occur.
Another (stranger) option would be to delete the setter on the prototype, though if the class is used elsewhere, outside of your code, it could cause problems:
class Foo {
set prop(arg) {
console.log('setter invoked');
}
}
delete Foo.prototype.prop;
const f = new Foo();
f.prop = 'val';
console.log(f.prop);
I am trying to implement a custom cell renderer to the pe:sheet component.
As this component is based on Handsontable, I tried the approach as described here:
https://handsontable.com/docs/6.2.2/demo-custom-renderers.html
I also changed the code for registering from Handsontable.renderers.registerRenderer('myRenderer', myCustomRenderer);
to
this.cfg.renderers.registerRenderer('myRenderer', myCustomRenderer);
in an attempt to access the instance of handsontable inside pe:sheet.
I am calling my sheetExtender via the extender attribute of pe:sheet.
function sheetExtender() {
// this.cfg.renderers.registerRenderer('myRenderer', myCustomRenderer);
// Handsontable.renderers.registerRenderer('myRenderer', myCustomRenderer);
console.log(this);
}
var myCustomRenderer = function (instance, td, row, col, prop, value, cellProperties) {
$(td).empty().append('TEST');
};
Adding 'myRenderer' to the colType attribute of a pe:sheetcolumn, I would expect the column values to be overwritten by 'TEST'.
When I use 'this.cfg...' I get an Uncaught TypeError: Cannot read property 'registerRenderer' of undefined.
When I use 'Handsontable...' I don't get the error, but no results either, as, I guess, this approach propably didn't add the renderer to the actual instance of handsontable.
Is there a way to add custom cell renderers in pe:sheet, or at least make a cell render HTML?
I am the author of pe:sheet. If you want to customize the renderer you can do the following...
This is where it happens in the component: https://github.com/primefaces-extensions/core/blob/master/src/main/resources/META-INF/resources/primefaces-extensions/sheet/1-sheet.js#L59-L116
You can just override the default TextCellRenderer with your own.
function sheetExtender() {
this.cfg.textCellRenderer = function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.HtmlRenderer.apply(this, arguments);
// call your custom renderer method here
myCustomerRenderer(instance, td, row, col, prop, value, cellProperties);
}
}
I'm passing an object from a parent component to a child component via Inputs(). I know because I'm passing an object and not a primitive type it's passing a reference to the object. Thus when the object changes in the parent I see it being reflected in the child.
What is the optimal way to pass an object via Inputs() that does NOT update the child component when it changes in the parent?
You need to have two properties that you use. One that you modify and a second that is passed to the child component but is a clone of the original.
#Component({..})
export class MyComponent implements OnInit {
// the original object value
public value: any;
// a value used by child components
public forChild: any;
public OnInit() {
// use deconstruction to make a copy
this.forChild = {...this.value};
// use assign to make a copy
this.forChild = Object.assign({}, this.value);
// use JSON to make a deep copy
this.forChild = JSON.parse(JSON.stringify(this.value));
}
}
As you mentioned:
When we pass objects using #Input(), it would be passed as a reference,
and When we pass primitive types, it would be passed as a value.
So i think one solution is to convert your object to string, and then pass it using #Input(). Later you can decode this stringifyed object to a object if you need.
Is it possible to use AutoMapper to map from Source to Destination conditionally resolving some properties based on the property value of another object? For example, mapping Source.Property to Destination.Property where ThirdObject.CountryCode.Equals("SomeCountry").
The current code base is setup so that values are being mapped from a DataReader to a list of objects. Then, if the ThirdObject.CountryCode has a certain value, then an amount property on the destination object must be multiplied by a multiplier.
Currently, I'm thinking of solving the problem by coming up with something like:
Mapper.Map<IDataReader, Destination>(dataReader)
.OnCondition(ThirdObject.CountryCode.Equals("SomeCountry")
.ForMember(destination => destination.Amount)
.UpdateUsing(new Multiplier(fixedAmount));
I'm hoping there is an easier way before going down that path.
Look at ResolveUsing:
Mapper.CreateMap<Journal_Table, Journal>()
.ForMember(dto => dto.Id, opt => opt.MapFrom(src => src.JournalId))
.ForMember(dto => dto.Level, opt => opt.ResolveUsing<JournalLevelResolver>().FromMember(name => name.Journal_level));
Then:
public class JournalLevelResolver : ValueResolver<string, JournalLevel>
{
protected override JournalLevel ResolveCore(string level)
{
...