Ive followed this example from another SO thread: X-editable custom field type not respecting overridden defaults and its helped me to create a similar custom field with x-editable. All is working ok but i cant figure out how render/display the 'text' of the select - the SO example ouputs the 'value'. my js to initialis the x-editable to use my custom inputs is thus:
我已经从另一个SO线程中跟随了这个例子:X-editable自定义字段类型不尊重被覆盖的默认值,它帮助我创建了一个类似x-editable的自定义字段。一切正常,但我无法弄清楚如何渲染/显示选择的'文本' - SO示例输出'值'。我的js到initialis x-editable使用我的自定义输入因此:
$('#stffulladdress').editable({
url : '',
pk : 6,
value : {
address : "",
city : "",
region : "",
postcode : "",
country : "eng"
},
sourceCountry: [
{ value: "eng", text: "ENGLAND" },
{ value: "ire", text: "IRELAND" },
{ value: "sco", text: "SCOTLAND" },
{ value: "cym", text: "WALES" }
],
validate : function(value) {
if (value.address == '' || value.postcode == '') return "Address first lines AND Postcode required";
},
display : function(value) {
if (!value) {
$(this).empty();
return;
}
console.log(value.country);
var html = $('<div>').html( value.address + '<br />' + value.city + '<br />' + value.region + '<br />' + value.postcode + '<br />' + value.country );
$(this).html(html);
}
});
My custom x-editable class is the same as the SO example mentioned with the only difference being i have more inputs -they work ok as expected. I would have thought that this snippet from the x-edit class gets the text of the selected item:
我的自定义x可编辑类与提到的SO示例相同,唯一的区别是我有更多输入 - 它们按预期工作正常。我原以为x-edit类中的这个片段会获取所选项目的文本:
value2html: function(value, element) {
if(!value) {
$(element).empty();
return;
}
var countryText = value.country;
$.each(this.sourceCountryData, function (i, v) {
if (v.value == countryText) {
countryText = v.text.toUpperCase();
}
});
var html = $('<div>').html( value.address + ',<br />' + value.city + ',<br />' + value.region + ',<br />' + value.postcode + ',<br />' + countryText );
$(element).html(html);
},
But upn displaying the selected country i still get the country value "eng" and not the text "England".
但是显示所选国家/地区我仍然获得国家/地区值“eng”而不是文本“英格兰”。
I've tried :
我试过了 :
value.country which gives me the value 'eng' and value.text gives undefined
value.country给我值'eng'和value.text给出undefined
Any idea how i can get the selected text??
知道我怎么能得到所选文本?
thanks
1 个解决方案
#1
0
Try the sourceCountry as follow:
尝试sourceCountry如下:
sourceCountry: [
{ "eng": "ENGLAND" },
{ "ire": "IRELAND" },
{ "sco": "SCOTLAND" },
{ "cym": "WALES" }
],
#1
0
Try the sourceCountry as follow:
尝试sourceCountry如下:
sourceCountry: [
{ "eng": "ENGLAND" },
{ "ire": "IRELAND" },
{ "sco": "SCOTLAND" },
{ "cym": "WALES" }
],