例如,我通过Json获取记录,并在成功函数中将返回数据存储在localstorage中以便使用
输出Json之类的 [{" 1":"核心"},{" 2":"中度"},{" 3" :"遥控"}]
它按预期返回
但我无法在下拉列表中填充数据,如果我硬编码相同的json它正在工作。在此先感谢请帮我解决。
$.ajax({
url: 'http://test.com',
//type: 'POST',
//data :Editorcontent,
success: function (data) {
let fieldes = JSON.parse(data)
localStorage.setItem('one',fieldes)
},
error: function () {
alert(url);
}
});
var selected = localStorage.getItem('one');
//selected = [{"1":"Core"},{"2":"Moderate"},{"3":"Remote"}]
//selected = selected.replace('\'',"'");
console.log(selected);
var editor = {
ajax: '',
ajaxFiles: '',
struct: {
buttons: ['top', 'bottom'] // buttons
},
fields: [
{
label: "Branch Name",
name: "DefaultBranchID",
values: selected,
type: 'select'
},
{
label: "Country:",
name: "CountryID",
type: 'multiselect',
attrs: [
{'pattern': '^[A-Za-z0-9_]+$'}
]
},
"选择"是分配的变量 分支出口OutPut下拉: - O/p