问题描述
我是 Backbone.js 和 javascript 世界的新手,我尝试创建一个下拉列表,并根据我想要填充其他表单元素的选择。在实现一些复杂的东西之前,我试图通过应用回调函数 console.log()
this.GetSelectedValue()
选定的值
AddSelectField (input_def ) {
var self = this
input_def.id = this.uid()
//const options = input_def.options
const options = input_def['test_param']['options']
const select = document.createElement('select')
select.id = `input-${input_def.id}`
select.onchange = this.GetSelectedValue()
for(var i = 0; i < options.length; i++) {
const opt = options[i][0];
const el = document.createElement("option");
el.textContent = opt;
el.value = options[i][1];
select.appendChild(el);
}
const row = document.createElement('div')
const title = document.createElement('div')
title.className = 'ui-from-title'
const TitleSpan = document.createElement('span')
TitleSpan.className = "ui-form-title-text"
TitleSpan.textContent = input_def.label
TitleSpan.style.display = 'inline'
title.append(TitleSpan)
row.className = 'ui-form-element section-row'
row.id = input_def.id
row.append(select)
row.append(title)
this.element.querySelector('.New-form').append(row)
return row
}
on-change 事件回调函数
GetSelectedValue () {
var e = this.element.querySelector('#input-uid-0');
var result = e.options[e.selectedindex].value;
document.getElementById("result").innerHTML = result;
}
这给了我一个错误 Uncaught TypeError: e is null
这意味着它无法捕获元素。
如何使用backbone.js 实现这一点
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)