I am newbie to extjs.I need to add/remove some values from extjs combo box base on some condition. I tried following code but no luck.
var obj =Ext.getCmp('filter');
var myArray=new Array();
myArray['id'] = 'a';
myArray['value'] = 'a';
var rec = new Ext.data.Record(myArray);
//obj.store.add(rec);
obj.store.removed(rec);
}
Use getById to find record for remove.
var combo = Ext.getCmp('filter');
combo.store.remove(combo.store.getById('a')); //typo: sotre corrected to store
combo.store.remove(combo.store.getById('a'));
obj.store.remove(rec);
removed is not a store function.
removed is a buffer array in which all removed recors are added.
if you're going to have a big store, you should keep this array empty, because removed objects are stored during all the session.
if the combo didn't change try to add store.sync() after adding or removing records
Related
var requiredFields = [1,3,5,7];
I am adding my required fields in an array. When i move to next page, i have to empty this array for new set of values. So I want to select this array using jquery and empty the array. Kindly advice.
This should work:
requiredFields = [];
Please find the updated fiddle in the comment section.
I have provided the HTML code and the ViewModel. On changing the value in drop down I want the pip value in grid to be updated. The pip value is getting calculated for new drop down value but the return is not able to bind the value to grid.
In order to make seats change in the UI on dropdownAValue change you need to declare empty observable array first:
self.seats = ko.observableArray();
And update it in the subscribe function instead of creating new observableArray every time:
self.seats([new PipCalculation(self.rates[0], self.rates[0].price, self.rates, self.newLot[0],currentlotvalue) ]);
See updated fiddle
well my answer will be addition to what Max Brodin has given .
We can further normalize you code by doing something like this
View model:
self.dropdownAValue = ko.observable(0.1);
self.seats = ko.observableArray([]);
var newItems = ko.utils.arrayMap(self.rates,function(item){
return new PipCalculation(item, item.price, self.rates, self.newLot[0], self.dropdownAValue)
});
self.seats(newItems);
//computed code
self.formattedPrice2 = ko.computed(function() {
//alert("hi");
var cur = self.rate().pair;
//var price = self.rate().price;
//alert(self.myQuote());
var price = self.myQuote();
var pip = 1;
var lot1 =currentlotvalue().lotSize;
Working fiddle here
Things to do :
There is no need to additionally write a subscribe for subscribing drop-down changes . All you need to do is send right DD value instance further in your case .
There is a performance hit as your are filling observablearray inside DD subscribe i.e every-time dropdown changes . That can be avoided by doing like i mentioned above.
Rather pushing into Observable array push into a normal array and the later using that array (performance improved) - max mentioned in his comments
There is a other way to do this like (i done previously like this)
self.seats([]);
var mutatedArray = self.seats();
ko.utils.arrayForEach(self.rates,function(item){
mutatedArray.push(new PipCalculation(item, item.price, self.rates, self.newLot[0],self.dropdownAValue)); // push to the array(normal array)
});
self.seats.valueHasMutated();
For more on this do refer my answer here .
When I do a find look-up on my table for hidden fields, I am seeing my two hidden fields. However, I want to further refine these 2 fields by their IDs. I notice that when I use find on the entire table using the "contains" that I get my 2 fields. However, if I do a find on the find results from the hidden fields, it returns an empty set. Can anyone explain why this is the case?
var table = sender.parentNode.parentNode.parentNode.parentNode;
// this finds my 2 hidden fields
var hidden_fields = $(table).find("input[type='hidden']");
// this finds each of the 2 fields individually by ID
var my_id_fieldA = $(table).find("[id*='hfMyIdFieldA']");
var my_id_fieldB = $(table).find("[id*='hfMyIdFieldB']");
// but this returns an empty set
var my_id_fieldA = $(hidden_fields).find("[id*='hfMyIdFieldA']");
You're looking for the filter function, not find. find selects child elements while filter filters the current selection.
Also there's no reason to find the table like that... try something like this.
var $table = $(sender).closest("table")
, $hidden_fields = $table.find("input[type='hidden']")
, $my_id_fieldA = $hidden_fields.filter("[id*='hfMyIdFieldA']")
, $my_id_fieldB = $hidden_fields.filter("[id*='hfMyIdFieldB']")
, $my_id_fieldA = $hidden_fields.filter("[id*='hfMyIdFieldA']")
;
I'm trying to sort data taken from a form and insert it into different arrays based on class assignments in the form. I am new to jquery and JS so this could be totally off base but here's what I'm trying to do:
<input type="text" id="word1" class="noun">Noun
and the scripts:
var noun = [];
// code that cycles through the form cut out.....
// here is the trouble spot:
var thing = $(this).val();
var whichArray = $(this).attr('class');
whichArray.push(thing);
Now if console.log the values everything looks good - I get the right info in both thing and whichArray but that push() command doesn't work.
I think the problem is that whichArray is a String, not an Array. You need to actually retrieve the array named whichArray. So you could modify your code thus:
var arrays = {};
arrays["noun"] = noun;
// your code here, then:
arrays[whichArray].push(thing);
I am storing some values in array like this.
var test = [];
I am pushing the values to this array as test.push(sample);
I have some logic for calculating this value
var sample= (a/b.length)*100;
When I click on a button, the above logic for calculating value of sample is done and once I got the value of sample I am pushing it to test[] array. Now I want to retrieve all the values from the test[] array whenever I check the checkbox. I am able to do all this but I am facing a problem here. only the last pushed value is saving. but I want to save all the values that are being pushed. can anyone please help me in solving this issue.
Quick response is needed and appreciated
Regards
Hema
You need to use 2 dimensional array for this.
Use
var test= new Array();
then assign value test['someKey']=sample;
or test.push(sample); . you can retrieve array value like alert(test[0]) or by iterating array with $.each(test,function(index,value){alert(value)});
What you want to do is create an Array which would function as a list of value sets.
You would then be able to push all the changes into an array, and put it in the list.
for instance:
var mainList = new Array();
var changeListA = new Array();
var changeListB = new Array();
// do some stuff on change list **a** .. push(something)
changeListA .push(something);
changeListA .push(something);
changeListA .push(something);
// do some stuff on change list **b** .. push(something)
changeListB .push(changeListB);
mainList.push(changeListA);
Your question is not perfectly clear to me, however I can at least provide a small jsFiddle that proves to you that (how) array.push works.
Other answers indicate that what you want is either a two dimensional array, or a "hashmap" or "associative array" where the array values are stored using a key name. The code here can be used in the fiddle to achieve either or...
http://jsfiddle.net/xN3uL/1/
// First if you need 2 dimensional arrays:
myArray.push( ["Orange", "Apple"] );
myArray.push( ["Mango", "Pineapple"] );
// Secondly, if you need hashmap or associative array:
var myObj = {};
myObj['key'] = 'value';
alert(myObject.key);