stateId config choosing in ExtJS - extjs

Should stateId be meaningful or a random string is sufficient?
stateId:"gridState"
is good but useless, can i just type
stateId:"aERDRasd"
What is your idea?
what can I do?

The value for the stateId config option can be any value, even a random one, provided it is unique for your ExtJS application and consistent across page/site reloads.

don't use a random string because it could conflict with another "random" string causing you hours of debugging later on.
instead, use something that you know will be unique and consistent due to the coding standards you decide to follow.
for example, i use state followed by the widget.alias in camelCase instead of lowercase like this...
Ext.define('my.view.user.ContactList', {
extend: 'Ext.grid.GridPanel',
alias: 'widget.contactlist',
stateId: 'stateContactList',
...

Related

The fields of Model in Extjs4 can not contains some special characters, such as dot, dash

I have to maintain a legacy project which developed by extjs4.2. But i found the grid cannot use a store with dynamic fields. And the field contains character dash and minus that cause errors. Please just take a look the following code snippet and focus on the fields of the grid store. It will throw syntax error 'Invalid left-hand in assignment'.
Ext.create('Ext.grid.Panel',{
title:'mygrid',
store: Ext.create('Ext.data.Store'{
fields:['group','alfa=-2.0','alfa=0','alf=2.0'],
data:[
{'group':'beta', 'alfa=-2.0':1.3, 'alfa=0':1.4, 'alfa=2.0':1.5 },
{'group':'beta', 'alfa=-2.0':1.3, 'alfa=0':1.4, 'alfa=2.0':1.5 },
]
}),
columns:[
{'dataIndex':'group','header':'group'},
{'dataIndex':'alfa=-2.0','header':'alfa=-2.0'},
{'dataIndex':'alfa=0','header':'alfa=0'},
{'dataIndex':'alfa=2.0','header':'alfa=2.0'}
]
});
Your sample contains a syntax error. Ext.create('Ext.data.Store'{ there is a , missing after the first argument.
In the background Ext is calling recordDataExtractorTemplate what will try to access the record values with the dot notation. This results a code value = source.alfa=-2 && source.alfa=-2.0; what is obviously syntactically incorrect.
Any of the solutions below may work. It is up to you which one you go for.
The quickest solution to change the field names in your code if possible if those fields are not used widely in the app.
You can check if later versions of Ext fixes this problem. However the migration can be a pain.
You can create an override of Ext.data.reader.Reader and patch the failing function.

Inflector not respecting custom rules

Using CakePHP 3.7.
I have added, at the bottom of config/bootstrap.php:
Inflector::rules('irregular', ['thesis' => 'theses']);
and actually, I've tried
Inflector::rules('irregular', ['theses' => 'thesis']);
just in case I had it backwards.
And in a cell I am trying to use:
use Cake\Utility\Inflector;
$singular_and_plural = [Inflector::singularize($base_name), $base_name];
The result for singularizing the word "thesis" is "thesiss".
Can anyone point out what's wrong, here?
The first form is the correct one, the key is the singular value, and the value the plural value.
That being said, what you're showing here is incorrect/problematic usage of Inflector::singularize(), as you're passing a value to it that already is singular, doing that often gives you unexpected/wrong results. You could open an issue ticket in such cases, sometimes this can be fixed in the core, but often times it's simply not possible as it would conflict with existing, required rules.
It should also be noted that CakePHP can handle thesis/theses out of the box already, it has singular/plural rules that match that. Make sure that you are passing in the expected values, and that you don't have additional custom rules that may interfer with what you're trying to inflect.

What are the valid symbols for a React 'key'

What are the valid symbols for a react key prop as such;
<div key="can i use spaces for example?"></div>
In my case I want to use a URL as the key
const links = [
{
label: 'foo label',
href: 'https://example.com/foo',
},
{
label: 'bar label',
href: 'https://example.com/bar',
}
]
links.map(
link => (<a key={link.href} href={link.href}>{link.label}</a>)
);
Is this valid? I was thinking that I could use some hash function to pass the href through first, but this is a pointless step if any character is guaranteed to be valid in a key value.
The reason I'm asking is that I can't find any example in the doc that uses a non-alpha-numeric character for the key, and also explicitly says that, if you don't have an ID to use as key for the object you're rendering you can hash some part of it to make a key. Although this could be because you shouldn't use very long keys, and should therefor hash the content first to truncate it's size, it seems that the whole documentation implicitly says that only alpha-numeric characters should be used as a key.
Requirements for React's key is best described in the documentation for reconciliation
In practice, finding a key is not really hard. Most of the time, the
element you are going to display already has a unique id. When that's
not the case, you can add a new ID property to your model or hash some
parts of the content to generate a key. Remember that the key only has
to be unique among its siblings, not globally unique.
So, the key should be unique (amongst its siblings) and stable.
Your example, therefore, is a good fit. Spaces should be fine as well.

Angular replace one word in many translation depend on flag

I have problem with one task. I am using:
"angular": "~1.2.16",
"angular-translate": "2.1.0",
The problem is that I need to change for example word 'bug' to 'issue' in all my translation which contain this word, depend on the toggle button. Is there an easy way to do this? I thought about some listener which will replace this word after translate finished. Or maybe there is a way to put parameter into translation string and replace it with some global variable which will hold word I need.
Could you give me some advice here, maybe provide some examples how can I solve this problem?
'angular-translate' is dummy as tree: it has key-value pairs picked from corresponding language object and maps key to values. So if you use angular-translate module, you have js object, that describes your dictionary. In each of this objects you should to create pair with key 'BUG' and value 'bug' or 'issue' depend on language.

How to declare, same webelement with different ids using Findby?

For instance, is it possible to define:
#FindBy(By.id("id1") OR By.id("form1:id1"))
public WebElement button
So that button having either "id1" or "form1:id1" should work fine?
You can use the #FindBys annotation, the syntax is:
#FindBys({#FindBy(id = "foo"),
#FindBy(className = "bar")})
The JavaDoc describes it here:
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/FindBys.html
Well,
use whathever you want, as long as it works
Personally I would use #FindBy(By.id("id1")) but it is just point of choice.
Also, there is no value added in referring same element twice with two different methods. It will only cause mess in your code
EDIT
As I understood your comment, there is element on the page which constantly changes its ID. If you need to refer to such elements, try using xPath See for example this xpath tutorial
The idea is that you will point to some place in the DOM rather than to specific ID
Use Xpath or CSS selector to do that. Or Java to store the ID name in String and then you can fill it to your Id.

Resources