function doMagic(path) {
$.getJSON(path, function (data) {
$(data).each(function(index, item) {
$('#table').append(
'<tr><td class="col1">'+ item.title01 +'</td><td class="col2">' + item.shopcode + '</td><td> <a href="' + item.link + '">' + item.title + '</a></td><td class="col3">' + item.cost + '</td></tr>'
);
});
});
}
doMagic('/js/db04.json')
doMagic('/js/db05.json')
// или
['/js/db04.json', '/js/db05.json', '/js/db06.json'].forEach(doMagic)
function getJsonAndUpdateTable(jsonPath) {
$.getJSON(jsonPath, function (data) {
$(data).each(function(index, item) {
$('#table').append(
'<tr><td class="col1">'+ item.title01 +'</td><td class="col2">' + item.shopcode + '</td><td> <a href="' + item.link + '">' + item.title + '</a></td><td class="col3">' + item.cost + '</td></tr>'
);
});
});
}
var data = []
$('#txt-search').keyup(async function(){
var searchField = $(this).val();
if(searchField === '') {
$('#filter-records').html('');
return;
}
if (!data.length) {
data = await fetch('url/to/file.json').then(r => r.json())
}
var regex = new RegExp(searchField, "i");
var output = '<div class="row">';
var count = 1;
$.each(data, function(key, val){
if ((val.employee_salary.search(regex) != -1) || (val.employee_name.search(regex) != -1)) {
output += '<div class="col-md-6 well">';
output += '<div class="col-md-3"><img class="img-responsive" src="'+val.profile_image+'" alt="'+ val.employee_name +'" /></div>';
output += '<div class="col-md-7">';
output += '<h5>' + val.employee_name + '</h5>';
output += '<p>' + val.employee_salary + '</p>'
output += '</div>';
output += '</div>';
if(count%2 == 0){
output += '</div><div class="row">'
}
count++;
}
});
output += '</div>';
$('#filter-records').html(output);
});
var dataPromise = fetch('url/to/file.json').then(r => r.json())
$('#txt-search').keyup(async function(){
var searchField = $(this).val();
if(searchField === '') {
$('#filter-records').html('');
return;
}
const data = await dataPromise;
var regex = new RegExp(searchField, "i");
var output = '<div class="row">';
var count = 1;
$.each(data, function(key, val){
if ((val.employee_salary.search(regex) != -1) || (val.employee_name.search(regex) != -1)) {
output += '<div class="col-md-6 well">';
output += '<div class="col-md-3"><img class="img-responsive" src="'+val.profile_image+'" alt="'+ val.employee_name +'" /></div>';
output += '<div class="col-md-7">';
output += '<h5>' + val.employee_name + '</h5>';
output += '<p>' + val.employee_salary + '</p>'
output += '</div>';
output += '</div>';
if(count%2 == 0){
output += '</div><div class="row">'
}
count++;
}
});
output += '</div>';
$('#filter-records').html(output);
});
header nav ul li ul {
background: #f7f7f7;
}
<nav class="navigation">
<ul class="menu">
<li class="menu__item">
<a href="#" class="menu__link">О Нас</a>
</li>
<li class="menu__item">
<a href="#" class="menu__link">Услуги</a>
<ul class="menu__sub">
<li class="menu__sub-item">
<a href="#" class="menu__link menu__link_sub">Ссылка 1</a>
</li>
<li class="menu__sub-item">
<a href="#" class="menu__link menu__link_sub">Ссылка 2</a>
</li>
</ul>
</li>
<li class="menu__item">
<a href="#" class="menu__link">Вакансии</a>
</li>
<li class="menu__item">
<a href="#" class="menu__link">Новости</a>
</li>
<li class="menu__item">
<a href="#" class="menu__link">Соглашение</a>
</li>
</ul>
</nav>
++
ты инкрементируешь (увеличиваешь на 1) значение переменной.++x
и x++
. О различиях почитай тутa == 1
, то на второй строке x = ++a + ++a => x = 2 + 3 => x = 5
. Соответственно, x == 5
, a a == 3
x += a => x = x + a => x = 5 + 3 => x = 8
var fs = require('fs');
var source = fs.readFileSync('./template.html', 'utf8');
var template = handlebars.compile(source);
var html = template(data);
console.log(html);
var fs = require('fs');
fs.readFile('./template.html', 'utf8', function(err, source) {
var template = handlebars.compile(source);
var html = template(data);
console.log(html);
});
Если можете, приведите примеры использования данного метода, ну и конечно объясните мне мои вопросы, спасибо!
Function.prototype.method = function(name, func){
this.prototype[name] = func;
return this
};
function Person(name) {
this.name = name
}
Person
.method('say', function() {
console.log('dude!')
})
.method('myName', function() {
console.log(this.name)
});
var person = new Person('Alex')
person.say() // dude!
person.myName() // Alex
gulp.task('html:build', function() {
gulp.src('src/[^_]*.html')
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(gulp.dest('build/'));
});
@@include('./_includes/_module.html')
const sums = arr.reduce((acc, n, i) => (
(i & 1) || acc.push(0),
acc[acc.length - 1] += n,
acc
), []);
// или
const sums = arr.reduce(
(acc, n, i) => (acc[i / 2 | 0] += n, acc),
Array(Math.ceil(arr.length / 2)).fill(0)
);
// или
const sums = Array.from(
{ length: arr.length / 2 + arr.length % 2 },
(n, i) => arr[i * 2] + (arr[i * 2 + 1] || 0)
);
// или
const sums = eval(`[${arr}]`.replace(/(\d+),(\d+)/g, '$1+$2'));
const result = sums.join(' ');
// или
const result = sums.reduce((acc, n) => acc + (acc && ' ') + n, '');
// или
const result = ''.concat(...sums.flatMap((n, i) => i ? [ ' ', n ] : n));
// или
const result = String(sums).replace(/,/g, ' ');