var arr1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
var arr2 = [1, 2, 3, 4, 5, 6, 7, 8];
var arr3 = [];
arr1.forEach(function(value, index) {
arr3.push(value);
if (index % 2 == 1) {
arr3.push(arr2.shift()); // Изменяет arr2!
}
});
console.log(arr3);
site.get_discount_price(discount_id).done(function(data) {
var discr_price = data.summa_vozvrata;
console.log(discr_price);
});
// EDIT
site.get_discount_price = function(discount_id) {
var result;
jQuery.ajax({
url: '/test.php/' + discount_id + '.json',
dataType: 'json',
async: false,
success: function (data) {
result = data.summa_vozvrata;
}
});
return result;
}
$( ".selector" ).datepicker({
closeText: "your close text"
});
<!-- inside view init -->
this.model.on('change', function updateView() { } );
<!-- view property -->
events: {
'input keyup': 'updateModel'
}
var a = [{x: 1, y: 1}, {x: 2, y: 2}];
var b = cloneArray(a);
b[0].x = 5;
console.log(a);
console.log(b);
function cloneArray(arr) {
var result = [];
arr.forEach(function(value) {
if (!isPrimitive(value)) {
value = copy(value);
}
result.push(value);
});
return result;
}
function isPrimitive(value) {
// string, boolean, number
return value == null || /^[sbn]/.test(typeof value);
}
// корректно работает только для простых объектов
function copy(value) {
return JSON.parse(JSON.stringify(value));
}
angular.module('toster', [])
.controller('MainCtrl', function($scope) {
$scope.data = {
price: 0,
count: 0
};
$scope.$watchCollection('data', function(data) {
var computed = 0;
var count = parseInt(data.count, 10);
if (count) {
computed = Math.round(data.price * count / 100);
}
$scope.computed = computed;
});
});
var map = new ymaps.Map(...);
$modal.on('shown.bs.modal', function() {
map.container.fitToViewport();
});