如何在 SapUi5 中创建动态 DropDownBox?
How can I create a Dynamic DropDownBox in SapUi5?
我在 ProjectExplorer 中有一个测试文件夹。在该文件夹中,我有多个 JSON 文件。我想创建一个 DropDownBox,它将包含该文件夹中的所有文件名。此外,当我单击任何文件时,我想在 TextArea 中显示该文件。我想在 SapUi5 中执行此操作。请建议
到目前为止我尝试了什么
var oText = new sap.ui.commons.Label({
text : "Saved Files"
});
var SavedFiles = new sap.ui.commons.DropdownBox();
var oItem = new sap.ui.core.ListItem();
#!/usr/bin/perl
$basedir = "data"; //folder location
@files = ('*.json');
chdir($basedir);
foreach $file (@files)
{
$ls = `ls $file`;
@ls = split(/\s+/,$ls);
foreach $temp_file (@ls)
{
if (-d $file)
{
$filename = "$file$temp_file";
if (-T $filename)
{
push(@FILES,$filename);
}
}
elsif (-T $temp_file)
{
push(@FILES,$temp_file);
}
}
}
foreach $FILE (@FILES)
{
oItem.setText("filename");
SavedFiles.addItem(oItem);
}
可以做到,但您需要使目录可浏览。
在需要阅读的目录下创建一个.htaccess
文件,并在该文件中添加以下内容:
Options +Indexes
执行以下操作:
var aFiles = [];
$.ajax({
url : "http://localhost:8010/", // or whatever URL you use
success: function (data) {
$(data).find("a").attr("href", function (i, val) {
if( val.match(/\.(json)$/) ) {
aFiles.push(val);
}
});
console.log(aFiles); //aFiles holds an array with all the *.json files
}
});
我在 ProjectExplorer 中有一个测试文件夹。在该文件夹中,我有多个 JSON 文件。我想创建一个 DropDownBox,它将包含该文件夹中的所有文件名。此外,当我单击任何文件时,我想在 TextArea 中显示该文件。我想在 SapUi5 中执行此操作。请建议
到目前为止我尝试了什么
var oText = new sap.ui.commons.Label({
text : "Saved Files"
});
var SavedFiles = new sap.ui.commons.DropdownBox();
var oItem = new sap.ui.core.ListItem();
#!/usr/bin/perl
$basedir = "data"; //folder location
@files = ('*.json');
chdir($basedir);
foreach $file (@files)
{
$ls = `ls $file`;
@ls = split(/\s+/,$ls);
foreach $temp_file (@ls)
{
if (-d $file)
{
$filename = "$file$temp_file";
if (-T $filename)
{
push(@FILES,$filename);
}
}
elsif (-T $temp_file)
{
push(@FILES,$temp_file);
}
}
}
foreach $FILE (@FILES)
{
oItem.setText("filename");
SavedFiles.addItem(oItem);
}
可以做到,但您需要使目录可浏览。
在需要阅读的目录下创建一个
.htaccess
文件,并在该文件中添加以下内容:Options +Indexes
执行以下操作:
var aFiles = [];
$.ajax({
url : "http://localhost:8010/", // or whatever URL you use
success: function (data) {
$(data).find("a").attr("href", function (i, val) {
if( val.match(/\.(json)$/) ) {
aFiles.push(val);
}
});
console.log(aFiles); //aFiles holds an array with all the *.json files
}
});