我已经在全球和本地安装了gulp
npm install gulp
npm install gulp -g
npm install gulp-util
npm install gulp-util -g
Run Code Online (Sandbox Code Playgroud)
当我尝试运行gulp我得到
'gulp' is not recognized as an internal or external command, operable program or batch file.
运行npm list gulp(或-g),我gulp@3.7.0有全局或本地gulp安装的位置.
我试过运行node gulpfile.js指向我的gulpfile,它运行没有错误,当然,它开始require('gulp').
关于让gulp在Windows上运行的任何建议(8.1)?
我知道我可以测试一个javascript变量然后定义它,如果它是未定义的,但是没有一些方法可以说
var setVariable = localStorage.getItem('value') || 0;
似乎是一种更清晰的方式,我很确定我已经在其他语言中看到过这种情况.
我有两个表date和id字段表.我想加入这两个领域.我试过了
JOIN t2 ON CONCAT(t1.id, t1.date)=CONCAT(t2.id, t2.date)
Run Code Online (Sandbox Code Playgroud)
这是有效的,但它很慢.有一个更好的方法吗?
我正在构建一个角度指令,它将在几个不同的位置使用.我不能总是保证使用该指令的应用程序的文件结构,但我可以强制用户将directive.js和directive.html(而不是真正的文件名)放在同一个文件夹中.
当页面评估时directive.js,它认为它templateUrl是相对于它自己的.是否可以将其设置templateUrl为相对于directive.js文件?
或者建议只在模板中包含模板.
我想我可能想根据不同的情况加载不同的模板,所以我宁愿能够使用相对路径而不是更新 directive.js
我正在尝试用JavaScript构建一个小日历.我的日期在Firefox和Chrome中运行良好,但在IE中,日期函数返回NaN.
这是功能:
function buildWeek(dateText){
var headerDates='';
var newDate = new Date(dateText);
for(var d=0;d<7;d++){
headerDates += '<th>' + newDate + '</th>';
newDate.setDate(newDate.getDate()+1);
}
jQuery('div#headerDates').html('<table><tr>'+headerDates+'</tr></table>');
}
Run Code Online (Sandbox Code Playgroud)
dateText是本周的星期一,它实际上是以'm,d,Y'的格式在php中设置的,例如"02, 01, 2010".
我有一个javascript函数,我想返回我在返回方法后得到的值.比说明更容易看到
function getValue(file){
var val;
lookupValue(file).then(function(res){
val = res.val;
}
return val;
}
Run Code Online (Sandbox Code Playgroud)
承诺的最佳方式是什么?据我所知,它return val会在lookupValue完成它之前返回,但是我不能return res.val因为那只是从内部函数返回.
我正在尝试为数组中的每个哈希获取一个键的子集.
哈希实际上要大得多,但我认为这更容易理解:
[
{
id:2,
start: "3:30",
break: 30,
num_attendees: 14
},
{
id: 3,
start: "3: 40",
break: 40,
num_attendees: 4
},
{
id: 4,
start: "4: 40",
break: 10,
num_attendees: 40
}
]
Run Code Online (Sandbox Code Playgroud)
我想只得到id和start价值观.
我试过了:
return_keys = ['id','start']
return_array = events.select{|key,val| key.to_s.in? return_keys}
Run Code Online (Sandbox Code Playgroud)
但是这会返回一个空数组.
我一直在研究这个问题几个小时试图弄清楚为什么所谓的简单自动完成没有出现.
事实证明,在我的代码中,输入元素被设置为autocompete="off",而pac-container上的样式是display: none.
我可以在DevTools中更改这些值,并且它工作正常,但我无法弄清楚这些值是如何或为何设置为这些值.
我的自动完成功能是在Angular Directive中设置的,就像这样,loadGmaps获取google api.
template: '<input id="google_places_ac" name="google_places_ac" type="text" class="input-block-level"/>',
link: function($scope, elm, attrs){
loadGmaps().then(function(){
var autocomplete = new google.maps.places.Autocomplete($("#google_places_ac")[0], {});
console.log(autocomplete);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
$scope.position = {
lat: place.geometry.location.lat(),
lon: place.geometry.location.lng()
};
$scope.$apply();
});
});
---------------------更新---------------------------- ------------------
希望没有其他人误入歧途,这autocomplete="off"有点误导.即使使用autocomplete="off",自动完成仍然有效,所以这不是问题.我正在覆盖.pac-container元素的css ,它保存了结果
.pac-container { //this is a fix for google autocomplete not showing up
z-index: 10000 !important;
display: block !important;
}
这个问题是,一旦从自动完成中选择了一个项目,自动完成仍然可见,我很确定有更好的方法来使用自动完成.
google-maps-api-3 google-places-api angularjs angularjs-directive
我有一个相当ajax重的站点,一些3k html格式的页面从ajax请求插入到DOM中.
我一直在做的是采用html响应,只使用jQuery插入整个东西.
我的另一个选择是输出xml(或可能是json),然后解析文档并将其插入页面.
我注意到似乎大多数大型网站都采用json/xml方式.Google Mail会返回xml而非格式化的html.
这是由于性能?还是有另一个理由使用xml/json vs只检索html?
从JavaScript的角度来看,它似乎注入直接html是最简单的.在jQuery中我只是这样做
jQuery.ajax({
type: "POST",
url: "getpage.php",
data: requestData,
success: function(response) {
jQuery('div#putItHear').html(response);
}
Run Code Online (Sandbox Code Playgroud)
我需要做xml/json响应
jQuery.ajax({
type: "POST",
url: "getpage.php",
data: requestData,
success: function(xml) {
$("message",xml).each(function(id) {
message = $("message",xml).get(id);
$("#messagewindow").prepend("<b>" + $("author",message).text() +
"</b>: " + $("text",message).text() +
"<br />");
});
}
});
Run Code Online (Sandbox Code Playgroud)
从代码的角度来看显然效率不高,我不能指望它是更好的浏览器性能,那么为什么第二种方式呢?
我正在使用node-webkit,我正在尝试让用户选择一个文件夹,然后我将返回该文件夹的目录结构并递归获取其子文件.
我用这个代码(在Angular Controller中)可以很简单地工作.
var fs = require('fs');
$scope.explorer=[];
$scope.openFile = function(){
$scope.explorer = [tree_entry($scope.path)];
get_folder($scope.path, $scope.explorer[0].children);
};
function get_folder(path, tree){
fs.readdir(path, function(err,files){
if (err) return console.log(err);
files.forEach( function (file,idx){
tree.push(tree_entry(file));
fs.lstat(path+'/'+file,function(err,stats){
if(err) return console.log(err);
if(stats.isDirectory()){
get_folder(path+'/'+file,tree[idx].children);
}
});
});
});
console.log($scope.explorer);
return;
}
function tree_entry(entry){
return { label : entry, children: []}
}
使用具有22个子文件夹和大约4个级别的中等大小的文件夹,需要几分钟才能获得整个目录结构.
有什么东西我在这里显然做错了吗?我不敢相信这需要很长时间,因为我正在使用内置的Node fs方法.或者有没有办法获取目录的全部内容而不触及每个文件?
我希望能够在树的所有方向上对文件名使用Angular过滤器,也可能在内容上使用Angular过滤器,因此延迟处理整个树并不是一个可行的解决方案.