【问题标题】:Insert Dynamic options into established <select> element of a kendo ui template?将动态选项插入剑道 ui 模板的已建立 <select> 元素?
【发布时间】:2017-05-05 21:36:33
【问题描述】:

我有一个名为 editor_template 的剑道模板,并且模板内有一个 &lt;select&gt; 元素。 &lt;select&gt; 是一个下拉列表,根据我们从用户那里获取的信息,它可以包含任意数量的任何名称的项目。所以我试图找到一种方法将&lt;option&gt; 元素插入到选择中,但到目前为止还没有运气。

我尝试过类似的方法:

$($('#editor_template').html()).find('#dropdownId').html().replace('variable', optionList);

它会抓取我的&lt;select&gt; 元素,并替换变量,但 editor_template 中没有反映任何变化。

我也尝试过使用.innerHTML 而不是html(),但没有成功。

简单地做:

$('#editor_template').html().replace('variable', optionList);

什么都没做。

我有&lt;select&gt;variable&lt;/select&gt;,所以替换变量应该可以,但它不会替换任何东西。

如何获得已经在剑道模板中明确说明的&lt;select&gt;,然后将我动态获取的任意数量的选项插入到下拉列表中?

【问题讨论】:

  • 我建议您在继续您的定制之前完全理解 here 所写的所有内容。
  • 谢谢,我还没有找到那个文档。关于设置变量然后为模板中的变量赋值的信息有望在这种情况下非常有用

标签: javascript jquery html kendo-ui kendo-template


【解决方案1】:

我没有看到 .replace() 是一个 jQuery 函数,我不清楚“变量”选择器是什么...

假设 dropdownID 是您的 &lt;select&gt; 标记的 ID,并且 optionList 包含 HTML,请尝试 $('#editor_template').find('#dropdownId').html(optionList);

【讨论】:

  • 好的,我试试看。 Replace 用于 JS 中的字符串,这就是为什么我调用 html() 函数以字符串形式获取它,然后对字符串进行替换
  • 应该可以,请参阅在 jsFiddle 上测试:jsfiddle.net/l0ul0u/sk71y7es
  • 我更改了我的变量,我的选项将转到 #=variable# 语法 kendo 说用于将 html 插入到模板中的变量中。然后使用: var template = kendo.template($('#editor_template').html()); $('#editor_template').html(template({whatIdOptions: whatOptString, whoIdOptions: whoOptString}));这让我的选项列表代替变量进入我的模板。感谢您的帮助!
猜你喜欢
  • 2015-02-26
  • 1970-01-01
  • 1970-01-01
  • 2021-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多