How to declare a variable and increment inside a for loop for each iteration in Xtemplate - extjs4.2

I'am using Extjs4.2.2. In my application i am using three loops, after the first loop i want to declare a variable and inside each iteration of second loop i want to increment the value and use the value in a class of a div. I have tried in the following way
'<tpl for="this.resources">',
'{% var parentIndex = xindex; %}',
'<tpl for="slots">',
'<div class="ext-cal-bg-row resource-slots-allocation tapaswini-'+(parentIndex++)+'" ></div>', // here i want to add the incremented value of parentindex to the class name tapaswini
'</tpl></tpl>',
But its giving error to me . Even am unable to access the "parentIndex" value.
Can anybody suggest where I'am missing. Any help is highly appreciated
Thanks in advance
Tapaswini

I found the solution
'<tpl for="this.resources">',
'{% var parentIndex = xindex; %}',
'<tpl for="slots">',
'<div class="ext-cal-bg-row resource-slots-allocation tapaswini-{[parentIndex++]} " ></div>',
'</tpl></tpl>',
By this am able to increment the variable
Thanks
Tapaswini

Related

How can I manipulate a string in dart?

Currently I'm working in a project with flutter, but I realize there is a need in the management of the variables I'm using.
Basically I want to delete the last character of a string I'm concatenating, something like this:
string varString = 'My text'
And with the help of some method or function, the result I get:
'My tex'
Am I clear about it? I'm looking for some way which helps me to 'pop' the last character of a text (like pop function in javascript)
Is there something like that? I search in the Dart docs, but I didn't find anything about it.
Thank you in advance.
You can take a substring, like this:
string.substring(0, string.length - 1)
If you need the last character before popping, you can do this:
string[string.length - 1]
Strings in dart are immutable, so the only way to do the operation you are describing is by constructing a new instance of a string, as described above.
var str = 'My text';
var newStr = (str.split('')..removeLast()).join();
print(newStr);
Another way:
var newStr2 = str.replaceFirst(RegExp(r'.$') , '');
print(newStr2);

Protractor - unable to get h2 value

I'm unable to get value from h2 tag using protractor.
Html Code:
<h2 class="ng-binding">7</h2>
I need this 7 value. This is from website "http://juliemr.github.io/protractor-demo/". I am adding 5+2.
Appreciate your help.
Try xpath
Here I am getting the element with ID, moving one position back and then looking for the h2
var result = element(by.xpath('//*[#id=\'gobutton\']/../h2'))
result.getText().then(function(value){
expect(value).toBe('7');
})
Or look directly to the h2:
element(by.xpath('//h2[#class='ng-binding']'))
In case you plan to always have 7 as a result then you can also look for the cssContainingText
var result = element.all(by.cssContainingText('.ng-binding', '7')).first();
in this case I am using .all and .first because this will return 2 elements so I am telling protractor to use always the first one
So your code should be something like this:
it('Should access the page and perform sum', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
element(by.model('first')).sendKeys(5);
element(by.model('second')).sendKeys(2);
element(by.id('gobutton')).click();
var result = element(by.xpath('//*[#id=\'gobutton\']/../h2'))
result.getText().then(function(value){
console.log('result is '+value)
expect(value).toBe('7');
})
});
As per the url given, After clicking Go it loads for some time. So add some wait and then try to getText() with the below locator.
browser.sleep(5000);
element(by.css('form>h2.ng-binding')).getText().then((text: String) =>{
expect(text).toBe("7");
})
Hope it helps you...
First, you find the element, for example with a by.css call. Then you use getText method to retrieve the desired tag content. Finally, you assert it to be equal to the value you expect:
result = element(by.css('h2.ng-binding'))
expect(result.getText()).toEqual('7')

How to insert an option value into a select tag with CasperJS?

Well, the question is very self-explanatory.
Right now, I'm front of a form which has a select tag with a couple of options already. But I must insert a new one, with a different value that I will receive from a .json file.
The thing is: I haven't been able to find a suitable solution from the CasperJS documentation.
I've tried something like this:
this.fill('form.coworkerdiscountcode', {
'CoworkerDiscountCode.DiscountCode': ['Value1']
});
But no results. Any ideas?
Thanks in advance.
You can execute any javascript code by passing it to casper.evaluate like this:
casper.evaluate(function() {
var x = document.getElementById("coworkerdiscountcode");
var option = document.createElement("option");
option.text = "Kiwi";
x.add(option);
});

'if' in ext.xtemplate for inexistent JSON object

My JSON has most of the time these two in its structure: "type" and "comments". Sometimes it has instead "type", "survey", "comments". So, I'd like to use "if" to let ext.xtemplate showing the ones it finds. For instance I've tried this but doesn't work:
new Ext.XTemplate(
'<div style="text-align:justify;text-justify:inner-word">',
'<b>Type:</b> {type}<br/>',
'<tpl if="survey">',
<b>Survey:</b> {survey}<br/>',
'</tpl>',
'<b>Comments:</b> {comments}',
'</div>'
I've tried instead these ones too but with no success:
<tpl if="survey != {}">
<tpl if="survey != undefined">
how could be the right way to detect an inexistent object?, thanks in advance.
PS. I'm using ExtJS 3.4
Use values local variable, for example:
var tpl = new Ext.XTemplate(
'<div style="text-align:justify;text-justify:inner-word">',
'<b>Type:</b> {type}<br/>',
'<tpl if="values.survey">',
'<b>Survey:</b> {values.survey}<br/>',
'</tpl>',
'<b>Comments:</b> {values.comments}',
'</div>'
);
Besides values there are also other variables available, which are helpful in some cases: parent, xindex, xcount.
Template after preprocesing is executed as a function, your template look like this:
function (values, parent, xindex, xcount){ // here are values, parent, etc
with(values){ // each property of values will be visible as local variable
return [
'<div style="text-align:justify;text-justify:inner-word"><b>Type:</b> ',
(values['type'] === undefined ? '' : values['type']),
'<br/>',
this.applySubTemplate(0, values, parent, xindex, xcount), // each <tpl> is converted into subtemplate
'<b>Comments:</b> ',
(values.comments === undefined ? '' : values.comments),
''
].join('');
}
}
This knowledge usually helps with understanding XTemplates.
Example usage of mentioned variables: http://jsfiddle.net/gSHhA/
I use <tpl if="!!survey>"

Dijit/Dojo Inline - Filtering Select - DataStore

I am using an inline filteringselect with datastore, as follows:
I am using ABBR as the identifier and NAME as the value.
The filtering selects and works correctly, but I have two issues.
Firstly, how do I retrieve the ABBR for the selected option NAME?
I have tried various things, including .innerHTML but that only retrieves the selected item name, not the identifier.
Secondly, when using the datastore option, how can I choose the default selected item, for example if it was a scale of 1 to 10 and I wanted 5 as the default selection, how can I do this?
Any ideas and advice would be greatly appreciated.
Mank thanks
dojo.addOnLoad(function() {
// inline store
str = new dojo.data.ItemFileReadStore({data: storeData10})
var itmes;
// for storing the store's items
str.fetch({
onComplete:function(itms){
itmes= itms;
console.log(itms)
}
})
dijit.byId("cmbx1").store = str
dojo.connect(dijit.byId("cmbx1"), 'onChange',function(){
//console.log(arguments);
//get the value u c in screen
var whatvseeinselect = dijit.byId("cmbx1").focusNode.value;
dojo.forEach(itmes, function(itm){
//compare the value u c in screen with store itms. once matched take that item and get the name attr or other attr if u require..
if(whatvseeinselect == str.getValue(itm,"name")){
console.log(str.getValue(itm,"name"));
}
})
})
});
I'm not sure whether this is the correct way.
Hope this helps