With a bootstrap 3, i try to make a single quote appear in x-editable select field as one of the possible choices.
使用bootstrap 3,我尝试在x-editable select字段中显示单引号作为可能的选择之一。
<a href="#" class="editable"
data-type='select'
data-value="[{value:'1',text:'I'm happy'},{value:'2',text:'or sad'}]">
Select me
</a>
In this example I'm trying to change the show "I'm happy" as one of the choices. I give the data in a JSON string through the data-value attribute.
在这个例子中,我试图改变节目“我很高兴”作为选择之一。我通过data-value属性在JSON字符串中提供数据。
That link is made editable (X-editable JS lib) with this function call:
使用此函数调用使该链接可编辑(X-editable JS lib):
$('.editable').editable({
mode: 'popup',
type: 'text',
success: function(response) {
}
});
Click on the link "Select me" and you will see an error in red from X-editable: "Error when loading list". (probably because my quote breaks the JSON structure).
单击“选择我”链接,您将看到X-editable中的红色错误:“加载列表时出错”。 (可能是因为我的报价打破了JSON结构)。
Here´s my problem in JSFiddle!
这是我在JSFiddle的问题!
Any suggestion to fix this is welcome. Thank you.
任何解决此问题的建议都是受欢迎的。谢谢。
1 个解决方案
#1
5
You're using incorrect attribute for source, should be like this:
您使用的属性不正确,应该是这样的:
<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>
From 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.值:初始值。应该为select类型定义以存储所显示文本的id。 source:select元素中的数据源。如果字符串 - 被认为是ajax加载项目的URL。否则应该是json。
And escape your quote with backslash.
用反斜杠来逃避你的引用。
#1
5
You're using incorrect attribute for source, should be like this:
您使用的属性不正确,应该是这样的:
<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>
From 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.值:初始值。应该为select类型定义以存储所显示文本的id。 source:select元素中的数据源。如果字符串 - 被认为是ajax加载项目的URL。否则应该是json。
And escape your quote with backslash.
用反斜杠来逃避你的引用。