开发者

Setting dropdown to first value

I have an .aspx hidden control that stores a defaultId for this dropdown. However, the values in开发者_StackOverflow the dropdown can change and sometime the defaultId is listed as one of the selections, other times it isn't. When the drop down clears we run this to reset it:

Global.getComponent("ddlVehicleType").setValue(Global.getComponent("DefaultVehicleTypeId").getValue());

Now when it sets that, if the dropdown doesn't have a value associated with that Id, it displays the actual Id in the field. I have a check for isNumeric now to see when that happens, but how do I make the field display the first value in the list of Id's it DOES have:

var displayedValue = Global.getComponent("ddlVehicleType").getRawValue();
            if (IsNumeric(displayedValue)) {

            }


Put together a unique little way of doing it, by going through the current populated store of that dropdown on the page:

var newId = 0;
var firstId = 0;
var typeStore = Global.getComponent("ddlVehicleType").getStore();
firstId = typeStore.getAt(0).get('LookupID');

typeStore.each(function(rec) {
    if (rec.get('LookupID') == Global.getComponent("DefaultVehicleTypeId").getValue())
    {
        newId = Global.getComponent("DefaultVehicleTypeId").getValue();
    }
});

if (newId != 0) {
    Global.getComponent("ddlVehicleType").setValue(newId);
} else {
    Global.getComponent("ddlVehicleType").setValue(firstId);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜