【问题标题】:Bootstrap typeahead and quoted stringBootstrap 预输入和带引号的字符串
【发布时间】:2012-11-28 21:10:48
【问题描述】:

我也有提到here的同样问题

<input type="text" class="span3" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source='["Amsterdam", "Maastricht"]' />

does work, but when using double quotes like

<input type="text" class="span3" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="['Amsterdam', 'Maastricht']" />

it won't work.

我实际上将它与 Angular + Angular-ui 一起使用

<input type="text" ng-model="mymodel" placeholder="Cities.."
                ui-jq="typeahead" ui-options="{source:cities}"/>

$scope.cities =["D","A"]

Typeahead 如果我将其更改为有效

$scope.cities =['D','A']

我需要用双引号字符串转换我的数组吗?如何。 native json有没有办法做到这一点。

谢谢。

【问题讨论】:

  • 我不熟悉 Angular-UI,但听起来它几乎是在替换 ui-options 属性中的 $eval'ed 项目......所以你最终会得到类似 @ 987654326@ 由于意外的引号而无法使用....我只是在猜测,但这很奇怪。您是否考虑过制作自己的自定义指令?应该不会太难。
  • 谢谢。根据您的提示,我更改为 ui-options='{source:cities}',从而解决了问题。您可以将其添加为答案,因此我可以接受。再次感谢。

标签: javascript twitter-bootstrap angularjs


【解决方案1】:

我不熟悉 Angular-UI,但听起来它几乎是在替换 ui-options 属性中的 $eval'ed 项目......所以你最终会得到类似 ui-options="{source:["D","A"]}"

编辑:就像你在评论中说的那样,用单引号括起来。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    • 2017-02-26
    • 2018-07-08
    • 1970-01-01
    相关资源
    最近更新 更多