Reputation: 3
I've a Page with 2 msDropDowns. After changing the value of the first list, I want to load the JSON Data for der 2nd list und alter the data.
$.ajax({
url: "http://foo.bar/data.json",
type: "POST",
data: {
article: produkt,
color: farbe,
size: groesse,
form: typ
}
}).done(function (data) {
var json = $.parseJSON(data);
$('#colors').msDropDown({
byJson:{
data: json.color,
name: 'color',
width: 220
}
}).data('dd');
In the documentation is no update-function :-(
So: How to alter the msDropDown List?
Upvotes: 0
Views: 2587
Reputation: 481
Try this one. It may help you.
$.ajax({
url: "http://foo.bar/data.json",
type: "POST",
data: {
article: produkt,
color: farbe,
size: groesse,
form: typ
}
}).done(function (data) {
var json_data = $.parseJSON(data.responseText.trim());
counter++;
for(var i=0;i<json_data.length;i++) {
json_data[i].text = json_data[i].NAME;
json_data[i].value = json_data[i].VALUE;
oHandler2.add(json_data[i]);//adding
}
oHandler2.showRows(json_data.length*h);
});
Upvotes: 0
Reputation: 174
if $('#colors') you are using div then replace with
//now code starts
//destroy dropdown before ajax call
var tempddl=$("#colors").msDropDown().data("dd");
tempddl.destroy();
$.ajax({
url: "http://foo.bar/data.json",
type: "POST",
data: {
article: produkt,
color: farbe,
size: groesse,
form: typ
},
success: function (data) {
var returnedata = data;
var ophtml='';
Y.each( returnedata, function( key, value ) {
//bind data into option filed if you want to display image then place image src in //title attribute
ophtml+='<option title='+returnedata[key].image+' value='+returnedata[key].value+'>'+returnedata[key].text+'</option>';
});
Y('#colors').html(ophtml);
Y("#colors").msDropDown().data("dd");
}
});
});
Upvotes: 2