我正在我的 spring 应用程序中使用 selectivity.js这是一个具有漂亮“标签外观”的选择库。现在我有一个 js 文件,我可以在其中配置选择性数据:
/**
*
*/
$(document).ready(
function() {
$('#single-input-with-labels').selectivity(
{
multiple : true,
items :
[
{
text : 'City',
children : [{
id : 1,
text : 'cityName1'
}, {
id : 2,
text : 'cityName2'
}, {
id : 3,
text : 'cityName3'
}]
}, {
text : 'Type',
children : [{
id : 4,
text : '2.1.typeName1'
}, {
id : 5,
text : '2.2.typeName2'
}, {
id : 6,
text : '2.3.typeName3'
}]
}
],
placeholder : 'ie. City, Type, ...',
searchInputPlaceholder : 'Type to search'
});
}
);
但我需要这样的配置:
{
multiple : true,
items :
[
{
text : 'City',
children : [{
id : 1,
text : 'cityName1'
}, {
id : 2,
text : 'cityName2'
}, {
id : 3,
text : 'cityName3'
}]
}, {
text : 'Type',
children : [{
id : 4,
text : '2.1.typeName1'
}, {
id : 5,
text : '2.2.typeName2'
}, {
id : 6,
text : '2.3.typeName3'
}]
}
],
placeholder : 'ie. City, Type, ...',
searchInputPlaceholder : 'Type to search'
}
在一些文件中,例如:“myData.txt”。在分析了一些数据之后,我将从 java 站点以编程方式构建这个 txt 文件。在下一步中,我需要从 js 函数中读取这个结构:
/**
*
*/
$(document).ready(
function() {
$('#single-input-with-labels').selectivity(
/* here I want to read this structure from the generated txt file
);
}
);
你知道如何从另一个文本文件中读取这种数据结构以使其工作吗?
最佳答案
为什么不将配置放在一个可以使用 $.ajax() 加载的 JSON 文件中?然后你可以这样做:
$(document).ready(function() {
$.ajax('/url/to/my/config.json').done(function(config) {
$('#single-input-with-labels').selectivity(config);
});
});
关于javascript - Spring + jsp + selectivity.js - 如何从 java 站点上构建的文件中读取选择性配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34765086/