我需要根据用户选择的下拉列表创建一定数量的对象。现在我有这个代码。
var driversFunc = function () {
var driversCount = osagoViewModel.fields.driversCount.selectedValue();
switch (driversCount) {
case "many":
return [];
case "1":
return [new driver()];
case "2":
return [new driver(), new driver()];
case "3":
return [new driver(), new driver(), new driver()];
case "4":
return [new driver(), new driver(), new driver(), new driver()];
case "5":
return [new driver(), new driver(), new driver(), new driver(), new driver()];
}
};
(使用knockout.js)