javascript - 带有单引号的 X 可编辑字段问题

标签 javascript json twitter-bootstrap-3 x-editable

使用 bootstrap 3,我尝试使单引号出现在 x-editable 选择字段中作为可能的选择之一。

<a href="#" class="editable" 
            data-type='select'
            data-value="[{value:'1',text:'I'm happy'},{value:'2',text:'or sad'}]">
  Select  me
</a>

在此示例中,我尝试将节目“我很高兴”更改为选择之一。我通过 data-value 属性以 JSON 字符串形式提供数据。

通过这个函数调用可以编辑链接(X-editable JS lib):

$('.editable').editable({   
    mode: 'popup',
    type: 'text',
    success: function(response) {
    }
 });

单击链接“选择我”,您将在 X-editable 中看到红色错误:“加载列表时出错”。 (可能是因为我的引用破坏了 JSON 结构)。

这是我在 JSFiddle 中遇到的问题!

欢迎提出任何解决此问题的建议。谢谢。

最佳答案

您使用的源属性不正确,应该是这样的:

<div style="margin: 150px">
    <a href="#" class="editable" data-type='select' data-value="1" data-source="[{value:'1',text:'I\'m happy'},{value:'2',text:'or sad'}]">Select  me</a>
</div>

来自 documentation :

value: initial value. Should be defined for select type to store id of shown text.
source: source for data in select element. If string - considered url for ajax to load items. Otherwise should be json.

并用反斜杠转义你的报价。

关于javascript - 带有单引号的 X 可编辑字段问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25198363/

相关文章:

javascript - Node js在查询记录时自动将MySQL中的GMT格式日期转换为本地格式

Javascript:在 settimeout 之前调用 cleartimeout 可以吗?

javascript - Json:编辑深度嵌套的值

html - 如何在 Bootstrap 中创建导航和选项卡样式?

css - Bootstrap CSS CDN 在某些系统中加载而不在其他系统中加载

javascript - 返回 JavaScript 中的函数输入

javascript - 在 JSON 对象中发送 Uint8Array (BSON)

json - 从 Hive 表中的 json 字符串中提取值

jquery - Bootstrap 3.3.2 模态事件多次触发

javascript - 使用ajax请求变量填充下拉列表