简体   繁体   English

在HTML页面上使用JavaScript动态添加剑道下拉列表

[英]Add a kendo drop down dynamically using javascript on html page

I'm trying to replicate the google forms for a personal website. 我正在尝试为个人网站复制Google表单。 The problem I've run into is dynamically creating the controls as the user adds another section. 我遇到的问题是在用户添加另一部分时动态创建控件。

I cannot create the javascript kendo drop down, can someone assist me with this, please. 我无法创建javascript剑道下拉菜单,请有人可以帮助我。

My code: 我的代码:

var IndexController = {

options: {
    count: 0
},

init: function () {
    var me = IndexController;
    me.bindEvents();

},

bindEvents: function () {
    var me = IndexController;
    var data = [
        { text: "Black", value: "1" },
        { text: "Orange", value: "2" },
        { text: "Grey", value: "3" }
    ];
    me.options.count = 0;
    //$("#Text").click(IndexController.AddText);
    //$('*[data-target="#addField"]').click(IndexController.AddActive);
},

AddNewSection: function () {
    var me = IndexController;
    $("#addNew").before('<div id="addNew" class="AddNew center">\
        <h4><label>Type</label></h4>\
        <input id="'+ me.options.count+'" value="1" style="width: 100%;" />\
    </div>');
    me.CreateDropDown(me.options.count);
    count++;
},

CreateDropDown: function (id) {
    var me = IndexController;
    ("#"+id+"").kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: me.bindEvents.data,
        index: 0,
        change: me.onChange()
    });
},

onChange: function () {

}
};

It adds the div but does not load the kendo drop down. 它添加了div但不加载kendo下拉菜单。 I get this error: 我收到此错误: 错误 The output: 输出: 产量

Kendo works in other parts of the website working with MVC. Kendo与MVC一起在网站的其他部分工作。 The scripts are all bundled. 这些脚本都捆绑在一起。

Thank you in advance 先感谢您

It's just seems like you forget to type $ at 37'th line. 好像您忘记在第37行输入$一样。

$("#type").kendoDropDownList({})

When error says "is not a function", that means either you typed incorrect function name or you are not accessing right element. 如果错误显示“不是函数”,则意味着您键入的函数名称不正确,或者您没有访问正确的元素。

In this case you are trying to reach kendoDropDownList function of "#type" string. 在这种情况下,您尝试访问“ #type”字符串的kendoDropDownList函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM