as I probably do not describe the problem in the right terms, I was not able to get an answer with google. Please excuse!
In the following code, I would like to replace 'hardcoded' identifier COMMENT with the variable editedField. How to do that?
var editedField:String = event.dataField;
if (model.multipleProcessingData[i][editedInformationProductNO].COMMENT != null{
...
}
Make sure you wrap this in try/catch block for NPE's, as you'll eventually find one with this many [] accessors.
A better, more OOP, would be to have an accessor function on your model that you can pass your data to:
model.getEditedField(i, editedInformatioNProductNO, editedField)
This will make it easier to troubleshoot and add good error messages to your app if things don't turn out like you expected.
var editedField:String = event.dataField;
if (model.multipleProcessingData[i][editedInformationProductNO][editedField] != null{
...
}
Related
The CSS.Pseudo types of csstypes have a bunch of CSS selectors like for ':hover' , ':active' and so on.
Is it possible to create a new type based on CSS.Pseudo, which accepts all the CSS.Pseudo types but with a '&' in front?
For example '&:hover', '&:active' and so on.
I want to be able to do something like
type CSS.Pseudo = ':hover' | ':active' ... etc.
type CssStyle= { [SOMETHINGSOMETHING CSS.Pseudo]: string}
const styles: CssStyle= {
'#:hover: someCssString, //OK
':hover: someCssString, //NOT OK
'&:hov': someCssString //NOT OK
}
I've tried a billion things on TS Playground but I feel I'm just not good enough at TS or it's just impossible.
You can't do this programmatically, at least as of TypeScript 3.5.
This has been suggested before, and the suggestion was closed as a duplicate of either a string literal key augmentation or a regular expression string literal validation suggestion, neither of which are particularly close to being incorporated into the language. If you really want to see this happen, you might want to go to one or both of those issues and give them a 👍 or possibly describe your use case if you think it's more compelling than what's already there.
Sorry this isn't the answer you probably want, but at least you can stop trying to get the compiler to do this for you. Good luck!
i wond if it's anyhow possible to solve this problem with Spacebars in Meteor:
{{TplVar placeholder="{{mf 'identifier' 'defaultval'}}"}}
This sytnax causes a syntax error.
If the placeholder would not contain spaces - as far as i know - just keeping it free of curly brackets would solve the solutions but this doesn't work here.
I'm a bit at a wall now - should there be really no way to solve it? I've already searched around for jagged handlebars/spacebars template tags but couldn't really find anything useful - especially not for the Meteor context.
Thanks in advance for helping!
Frank
I've never used the Messageformat package (which looks interesting), but from the docs it looks like there's a javascript API. So you can just do something like:
{{TplVar placeholder=thisPlaceholder}}
and
Template.yourTemplate.helpers({
thisPlaceholder: function() {
return mf(this.identifier, this.defaultval);
}
});
Note that I'm assuming identifier and defaultVal are in the data context here - if they're the results from helper functions, you need to replicate those functions within this new thisPlaceholder helper and replace this.identifier and this.defaultval with the results.
I'm currently developping a multi languages application using the tap-i18n package. I wonder how I can translate errors.
I can grab the code and then display a custom message that I would have written to the translation file before.
But I saw on this post there is a better way of doing this with another i18n package.
Does anyone know if there is way of doing something like with tap-i18n ?
EDIT : For now I'm doing something like this :
Meteor.call('createNewUser', newUser, function (error, ret)
{
if (!error)
displayError(TAPi18n.__('success'), TAPi18n.__('new_user_success'), TAPi18n.__('ok'), "btn-success btn-lg", "success-popup");
else
{
switch (error.error)
{
case 403:
displayError(TAPi18n.__('danger'), TAPi18n.__('new_user_already_exist'), TAPi18n.__('ok'), "btn-danger btn-lg", "danger-popup");
break;
default:
displayError(TAPi18n.__('danger'), TAPi18n.__('new_user_error'), TAPi18n.__('ok'), "btn-danger btn-lg", "danger-popup");
break;
}
}
});
My answer might be a bit off-topic, but do you mean application errors? If so, you shouldn't really return that to the users, as this could constitute a security flaw, giving them too much information.
From OWASP: https://www.owasp.org/index.php/Error_Handling
Thus, you might want to handle the errors, and give the users exactly what you want them to know.
Just include the error messages in your translation, and proceed as with normal strings to translate.
I hope this is of some help :).
EDIT:
I understand now what you mean. As far as I know, there's no such option, as there is with just-i18n. As a suggestion for unbloating the code a bit, you could use a helper function such as:
function t(keyToTranslate){
return TAPi18n.__(keyToTranslate)
}
And in the code:
displayError(t('danger'), t('new_user_already_exist'), t('ok'), "btn-danger btn-lg", "danger-popup");
A bit naive suggestion, but there's no functionality to map the errors in this package, as far as I know. The way you're handling it seems correct to me.
I have started to use Stackmob as a backend for a simple app I am building.
In stackmob I have set a relationship between two schema's and want to use '.fetchExpanded' to grab all of the data from stackmob, see this fiddle (will need to view the console to see the output):
http://jsfiddle.net/mcneela86/65Rax/
.fetchExtended(1);
The same code works using the '.fetch' instead of '.fetchExpanded'.
Has anyone come across this before?
Would really appreciate any help.
Ok, I found a work around for this.
Instead of using '.fetchExtended(1);' I will just use '.fetch();' and when I am defining the model I will change the following:
var Bike = StackMob.Model.extend({
schemaName: "bikes"
});
to:
var Bike = StackMob.Model.extend({
schemaName: "bikes?_expand=1"
});
This seems to remove the need for '.fetchExtended(1);'
Hope this helps someone else.
I searched far and wide to find a working solution to this but couldn't find it.
What I want to do is change the argument that is passed to the view because I want for pathauto cleaned taxonomy terms to work as an argument. I have a code that transforms cleaned term back to a original one, but cannot make the view use it.
I saw some people changing it in hook_preprocess_views_view(&$vars) but in my case (Views 2.11) has a argument in $vars instanced so many times that it's not the way.
Can anyone please help me change this argument?
There may be a better way but you could use views_embed_view() and set the arguments yourself
I have two ideas, either to add some custom php code to the view's argument's phpcode section that does something like this
$args[0] = 1;
return $args;
or try to use the function
hook_views_pre_view(&$view, &$display_id, &$args) {
// modify $args value here
}
didn't test them so don't know which will work.
I think hook_views_pre_view might help you do just that.