如何在按钮单击上添加一行? [英] How to add a row on button click?

查看:65
本文介绍了如何在按钮单击上添加一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在该小提琴中,有一个添加的 timing按钮.有默认行具有星期几下拉菜单,从时间文本字段到时间文本字段和医院下拉菜单.现在,当我单击添加计时按钮时,我希望另一行具有星期几下拉菜单,从时间文本字段到时间文本字段和医院下拉菜单.

in this fiddle there is an add timing button. There is default row having week day dropdown,from time textfield,to time textfield and hospital drop down.Now when I click on the add timing button I want another row having week day dropdown,from time textfield,to time textfield and hospital dropdown.

任何人都可以告诉我该怎么做吗?

Can any body please tell me how to do that?

这是我的淘汰赛代码

var DocSchedule = function (id, day, fromtime, totime, hospital, hospitalId) {
    this.id = ko.observable(id);
    this.day = ko.observable(day);
    this.fromtime = ko.observable(fromtime);
    this.totime = ko.observable(totime);
    this.hospital = ko.observable(hospital);
    this.hospitalId = ko.observable(hospitalId);
};

var Patientp = function () {
    this.id = ko.observable(idValue);
    this.name = ko.observable(nameValue);
    this.degree = ko.observable(degreeValue);
    this.gender = ko.observable(genderValue);
    //this.consultant= ko.observableArray(consultantArrValue);
    this.username = ko.observable(usernameValue);
    this.password = ko.observable(passwordValue);
    this.email = ko.observable(emailValue);
    this.mobile = ko.observable(mobileValue);
    this.imgFile = ko.observable(imgFileValue);
    this.imgSrc = ko.observable(imgSrcValue);
    this.imagePath = ko.observable(imagePathValue);
    this.userid = ko.observable(useridValue);
    this.department = ko.observable(departmentValue);
    //this.consultant= ko.observableArray(consultantArrValue);
    //this.consultant= ko.observable(consultantValue);
    this.addSlot = function (doctor) {


        var docSchedule = new DocSchedule();
        iter = iter + 1;
        docSchedule.id(iter);

    }


}
idValue = 'hi';
useridValue = 'hi';
nameValue = 'hi';
addressValue = 'adress';
genderValue = 'hi';
mobileValue = 'hi';
//these fields are not available
usernameValue = 'hi';
passwordValue = 'hi';
emailValue = 'hi';
imgFileValue = 'imagefileValue';
imgSrcValue = 'ui_resources/img/profile_pic.png';
imagePathValue = 'imagePathValue';
consultantArrValue = null; //'${currentpatient.user.name}';
consultantValue = "d1";
degreeValue = 'hi';
departmentValue = 'hi';



var iter = 0;
var patp = new Patientp();
ko.applyBindings(patp);

推荐答案

  1. 您在Patientp doctor.schedules.push(docSchedule);中没有observableArray时间表 引发未捕获的TypeError:无法读取未定义的属性'push'
  1. You don't have observableArray schedules in Patientp doctor.schedules.push(docSchedule); throws Uncaught TypeError: Cannot read property 'push' of undefined

尝试一下:

var iter = 0;
var DocSchedule = function (id, day, fromtime, totime, hospital, hospitalId) {
    this.id = ko.observable(id);
    this.day = ko.observable(day);
    this.fromtime = ko.observable(fromtime);
    this.totime = ko.observable(totime);
    this.hospital = ko.observable(hospital);
    this.hospitalId = ko.observable(hospitalId);
};

var Patientp = function () {
    this.id = ko.observable(idValue);
    this.name = ko.observable(nameValue);
    this.degree = ko.observable(degreeValue);
    this.gender = ko.observable(genderValue);
    this.username = ko.observable(usernameValue);
    this.password = ko.observable(passwordValue);
    this.email = ko.observable(emailValue);
    this.mobile = ko.observable(mobileValue);
    this.imgFile = ko.observable(imgFileValue);
    this.imgSrc = ko.observable(imgSrcValue);
    this.imagePath = ko.observable(imagePathValue);
    this.userid = ko.observable(useridValue);
    this.department = ko.observable(departmentValue);
    this.schedulers = ko.observableArray([]);
}
idValue = 'hi';
useridValue = 'hi';
nameValue = 'hi';
addressValue = 'adress';
genderValue = 'hi';
mobileValue = 'hi';
usernameValue = 'hi';
passwordValue = 'hi';
emailValue = 'hi';
imgFileValue = 'imagefileValue';
imgSrcValue = 'ui_resources/img/profile_pic.png';
imagePathValue = 'imagePathValue';
consultantArrValue = null;
consultantValue = "d1";
degreeValue = 'hi';
departmentValue = 'hi';

function vm() {
    var self = this;
    self.person = new Patientp();
    self.schedule = new DocSchedule();
    self.schedules = ko.observableArray([new DocSchedule(iter)]);

    self.addSlot = function () {
        console.log('added');
        iter++;
        var docSchedule = new DocSchedule(iter);
        self.schedules.push(docSchedule);
    };

    self.removeSlot = function () {
        console.log('removed');
        self.schedules.remove(this);
    }
};
var viewModel = new vm();
ko.applyBindings(viewModel, document.getElementById('addDoctorSchedules'));

这篇关于如何在按钮单击上添加一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆