我在一个数组上运行一个forEach循环并进行两次返回promises的调用,我想填充一个对象说this.options,然后用它做其他的事情.现在我遇到异步问题,如果我使用下面的代码示例,我首先进入then函数.
$.when.apply($, someArray.map(function(item) {
return $.ajax({...}).then(function(data){...});
})).then(function() {
// all ajax calls done now
});
Run Code Online (Sandbox Code Playgroud)
这是下面的工作代码,但它只适用于数组中的第一个元素,因为我.then在响应中调用了结果函数.我想首先对数组的所有元素进行所有获取,然后调用结果函数来执行某些操作.
array.forEach(function(element) {
return developer.getResources(element)
.then((data) = > {
name = data.items[0];
return developer.getResourceContent(element, file);
})
.then((response) = > {
fileContent = atob(response.content);
self.files.push({
fileName: fileName,
fileType: fileType,
content: fileContent
});
self.resultingFunction(self.files)
}).catch ((error) = > {
console.log('Error: ', error);
})
});
Run Code Online (Sandbox Code Playgroud)
如何self.files在forEach循环完成后填充对象,然后使用files对象调用生成的函数?
我在我的代码中实现了单选的插件选择.我正在尝试为搜索框添加占位符文本,但我无法.我试过以下的事情:
<select id="search_pi" name="search_pi" type="text" class="chosen-select"
style="width:450px;" onchange="this.form.submit()" >
<option value="">Search Project/Initiative...</option>
<?php
include "../includes/search_dropdown.php";
foreach($proj_ini_Array as $qa){
echo "<option value = \"$qa\">$qa</option>";
}
?>
Run Code Online (Sandbox Code Playgroud)
JS
<script>
$(document).ready(function() {
$('.chosen-select').chosen({
placeholder_text_single: "Select an option",
no_results_text: "Oops, nothing found!"
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
在选择字段中,我也尝试过使用,data-placeholder="Select an option"但这也无济于事.有人可以让我知道我错过了什么吗?
提前致谢.
我有一个代码,我在 header.php 中包含 jquery 文件和引导程序文件。我遇到了一些问题,如果我在 bootstrap.js 文件之前包含 jquery 文件,它会弄乱我网页上的其他选项卡,基本上即使我单击其他选项卡它也不会导航我。
我认为 jquery 和 bootstrap 之间存在冲突。我在下面粘贴我的 header.php 文件以供更多参考。
头文件
<?php require_once "essentials.php";
//error_reporting(~0);
//ini_set('display_errors', 1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--<style>{height:150px; width:1300px;}</style>-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="Public">
<title><?php echo $page_title?></title>
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script src="script_dbafactory.js?<?php echo rand(0,511);?>"></script>
<link href="css/bootstrap.css" rel="stylesheet">
<!--<link href="css/style_header.css" rel="stylesheet">-->
</head>
<body>
<div class="container">
<div class="row clearfix">
<div class="col-md-4 column">
<img alt="logo" src="./images/source.png"> …Run Code Online (Sandbox Code Playgroud) 我正在尝试压缩包含该.git目录的 git 存储库目录。我尝试在目录上执行 tar,但它创建了一个比原始文件夹更大的文件夹,因为它附加了所有子模块。
我已经尝试过以下命令,但它们在没有.git目录的情况下进行压缩 -
git archive master --format=tar --output="../gridImageSearch.zip"
以下命令使用.git目录进行压缩,但该文件夹太大 -
tar -zcvf ../blah.tar.gz blah
有什么建议么?