【问题标题】:How to create External data-source in html5如何在 html5 中创建外部数据源
【发布时间】:2013-08-28 13:30:47
【问题描述】:

在 html5 中,输入字段的格式如下

 <input type='text', data-provide= "typeahead", data-items="4",
 autocomplete="off",  data-source='["Business and Commercial Laws",
 "Consumer Laws", "Criminal Laws"]', name='userInputName',
 placeholder='Court of practice'> Data </input>

我如何创建与data-source 的链接,它不是内联的,而是外部的。我最终想重用数据源。

编辑: 我在引导程序中使用typeahead 插件。我在 node.js 框架中编程。所以我可以使用

- var ArrayVar = [ "this", "that", "here"]

 data-source='#{ArrayVar}' 

但上面将数组ArrayVar 转换为字符串"this, that, here",这是不需要的,因为data-source 应该是一个数组。

【问题讨论】:

  • “不是内联,而是外联”是什么意思。创建什么样的链接?
  • 上面的代码显示了data-sourceinput标签内内联定义。我想在其他地方提供一个链接,比如上面script标签或另一个文件中
  • 链接是指&lt;a&gt;?这和data-source 有什么关系?
  • 不,我的意思是data-source = "external link"外部链接可能是在script标签内定义的变量。如果那行得通。
  • 您是否正在使用一些特殊的插件/框架来评估这些属性? data-source 没有特定的 HTML5 输入属性。顺便说一句,&lt;input/&gt; 标签应该是空的。

标签: javascript node.js twitter-bootstrap bootstrap-typeahead


【解决方案1】:

可以使用 jQuery 检索数据属性。

$('[data-source']).each(function(){ // select all elements with the data-source attribute
    var $this = $(this), source = $this.data("source");

    // update the source
    $this.data("source", sourceToArray(source));
});

将其装入框架可能很困难,因此我建议选择一个未使用的属性,或者确保在加载 AngularJS 之前触发此代码。

【讨论】:

    猜你喜欢
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2021-08-01
    • 1970-01-01
    • 2016-08-19
    • 2019-12-07
    相关资源
    最近更新 更多