You are in a client script and taking the page.descendants (or pageFragment, popup, etc, whatever) and want to iterate its values, it's ok no problem:
app.popups.GlobalFilter.descendants.foreach(function (w){...})
But when you are in the closure you can't determine what kind of widget you dealing with, is it TextEdit or DatePicker, or Multiselect. All you have - properties (name, align, etc.). There is no property like ComponentClass, WidgetClass or ClassName.
You even can't set the values because you don't know what property you have to set (value for Datepicker and values for Multiselect) and it's type (Date for DatePicker and array for Multiselect).
I have to hardcode widget names with their types for now, but maybe I missed something and there is a way to determine widget/component class name?
Related
From the Lit documentation: "The component shouldn't change its own public properties, except in response to user input."
Also from the documentation: "Internal reactive state works just like public reactive properties, except that there is no attribute associated with the property."
However, when you declare a property, there is an option of setting attribute to false, which prevents an attribute from being associated with the property.
#property({attribute: false})
data = {};
What would be the purpose of doing this? Wouldn't the property just act like internal state at that point?
For reference, Lit already has several ways of declaring internal state variables, either with the #state decorator or setting the state option to true, so I'm just not sure why they allow this too.
I think the main use case for this is for when you have to pass big complex data to the component but want it to be set directly as a property and still get lit to rerender stuff for you.
I think this is easier to visualize with an example, let's say you're making a component which will render a list out of an array passed as a property.
If the array was set as an attribute, it would look something like this:
<list-renderer items='[{id: "1", name: "John Doe"}, {id: "2", name: "Alice Williams"}]'></list-renderer>
Now, this example only has two items, but it could be something way bigger, and that attribute will eventually need to be serialized into an array using JSON.parse() by lit. So, you're just doing an extra step, especially if you already had the array as a JS object rather than JSON data.
So, for this kind of cases it's easier to just force users to set items as a JS property directly.
This will also apply for when you need to pass complex configuration setting objects or functions to the component.
Then again, for most of the components you'll be making, you will probably stick with either having the attribute or making it a fully internal state property.
This way you are really free to use any combination.
A property which acts also as state and attribute
A property which acts also as state but not as an attribute
A state, which is not a property
A property, which is an attribute
A property which is not an attribute
see also https://javascript.info/dom-attributes-and-properties for the difference between properties and attributes.
I'm working with Xamarin Forms at the moment and I'm impressed by the MVVM concept and I try to use bindings as recommended. If I have a textfield that I want to display some text in I will bind that textfield to a string. The thing is though that I would like to bind this to a custom object-type instead. Let's say that it represents order id. The order id will be displayed as a string of a special format. Let's say it is always 10 characters, the 2 first are always country code, the rest are individual. This would be nice to have contained in an object that can validate it self. Is there any way that I can bind this custom object? How do I control how it is represented in the view? Should I use ToString()? This would be a bit unflexible since I would perhaps like to display this a bit differently in different context.
Any feedback would be helpful(except for the validation in itself for the order, I know how to do that).
Have you tried binding your text field to the custom object's property? Such as <Entry Text="{Binding CustomObject.Id}"/> or label.SetBinding(Label.TextProperty, "CustomObject.Id");
Label label = new Label();
// myObject is your custom object
label.BindingContext = myObject;
// MyPropertyName is some public property on your object you want to display
label.SetBinding(Label.TextProperty, "MyPropertyName");
I've looked in multiple places and cannot seem to find anything to work for my purpose.
I have this QComboBox that constantly changes (And could change after the program is completely finished).
To make it easier I made an Enum list for switch statements
public:
enum Race{
Race1,
Race2,
ect
}
The combo is filled with the same elements.
However, I want to make it even easier. So instead of changing the Combobox and changing the enum list, is there a way where all i have to do is add a new "race" to the enum list, that it will populate the combobox, so all i would have to do is a switch statement to handle new race?
Additional info:
I'm willing to put the enum list into a qstringlist.
I have Q_ENUMS (Race) set
Using Q_ENUMS will give you a way to iterate over your enum and add their enumerands to the combobox in a loop. However it will not give you the possibility to add a related GUI text for each enumerand. The enumerand name like it is written in your source code will be available only. Maybe your code side name is not what you want to see in your GUI as a text.
Remember that you can add any kind of QVariant supported user values to a combobox while you populate it with text strings... so you do not need to maintain an enumeration if there is some other kind key you can use instead.
I have an enum called SiteTypes that contains several values that are all bound to a dropdown list. On the client side, I need to check this dropdown to see if the selected value is one of those enum values. I don't want to hardcode the value of the enum in the script in case it needs to change, so I want to use a server tag to get it directly from the enum itself. Conecptually, I would like to do this:
function SiteIdChanged() {
var x = "<%=SiteTypes.Employee %>";
}
The way I am doing it now is created a protected property in the codebehind that returns that specific enum value and am doing this:
function SiteIdChanged() {
var x = "<%=EmployeeSiteTypeValue %>";
}
I don't like that, though, because I have to create a special property on every page that I need to do such a check.
Is there a way to do what I want here?
Are you getting a "xxx is inaccessible due to its protection level" error when you compile or run the page? enums are public by default, classes are not. My guess is that you've defined your enum inside your page's class and you aren't explicitly marking it with the 'public' access modifier. Explicitly mark it as public or move it outside of the class and see what happens. If you're planning on using it on lots of pages you should stick the enum definition in in a file in the App_Code folder of your project.
If you don't like your current implementation I would consider using a PageMethod to compare the dropdown selection to the enum value. This approach will probably be cleaner, as you can do most of the logic server-side.
Here's a tutorial on PageMethods:
http://blogs.microsoft.co.il/blogs/gilf/archive/2008/10/04/asp-net-ajax-pagemethods.aspx
As long as your enum is marked public, you can just go with your first option. There's no need to put a property on every single page you want to retrieve the value from.
That approach is really the simplest solution for writing out server side values in your JavaScript.
You can use the Enum.IsDefined Method this well tell you if the selected value from the dropdown is actually part of your enum.
Enum.IsDefined(typeof(MyEnum), myValue)
http://msdn.microsoft.com/en-us/library/system.enum.isdefined.aspx
How can I access the specific .data (based on its dataField) inside an AdvancedDatagridColumn-ItemRenderer instead retrieving the whole data for the parent AdvancedDataGrids dataprovider?
Any idea?
Many thanks...
In an itemRenderer, your dataProvider's object is passed in to the data property of the itemRenderer. Your itemRenderer will need to implement the IDataRenderer interface
http://livedocs.adobe.com/flex/3/langref/mx/core/IDataRenderer.html
Most Flex Framework Components already implement this interface.
The way that the DataGrid component works internally is to call an itemToLabel function ( http://livedocs.adobe.com/flex/3/langref/mx/controls/listClasses/AdvancedListBase.html#itemToLabel() ) to figure out the label to display. This function will look at the dataField and dateFunction and return a string representing your item.
The results of this function are passed into the itemRenderer as part of the AdvancedDataGridListData class. Take a look at the label property:
http://livedocs.adobe.com/livecycle/8.2/programLC/common/langref/mx/controls/advancedDataGridClasses/AdvancedDataGridListData.html
You can also use DataGridListData.owner to access the dataField directly, although that would be an unusual approach.