var arr = [{id: 1, label: 'test'},{id: 2, label: 'test1'},{id: 3, label: 'test2'},{id: 4, label: 'test3'},{id: 5, label: 'test4'},{id: 6, label: 'test5'}];
for(var i = 0; i < arr.length; i++){
$('селектор-куда-добавить-эту-структуру').append('<input type="checkbox" id="id'+arr[i].id+'" name="'+arr[i].label+'"/><label for="id'+arr[i].id+'">'+arr[i].label+'</label>');
}
var data = [
{id: 1, label: 'test'},
{id: 2, label: 'test1'},
{id: 3, label: 'test2'},
{id: 4, label: 'test3'},
{id: 5, label: 'test4'},
{id: 6, label: 'test5'}
];
$.each(data, function(key, value) {
var attr = $.extend(value, {
'id': 'id' + value.id,
'type': 'checkbox'
});
$('<input />').attr(attr).appendTo('body');
$('<label />').attr('for', attr.id).text('text' + (key || '')).appendTo('body');
});
$.each([{id: 1, label: 'test'},{id: 2, label: 'test1'},{id: 3, label: 'test2'},{id: 4, label: 'test3'},{id: 5, label: 'test4'},{id: 6, label: 'test5'}], function(item) {
$('body').append('<input type="checkbox" id="id' + item.id + '" name="test"/><label for="id"'+ item.id + '">' + item.label + '</label>');
});
.then(function (response) {
params.total(response.total);
$scope.users = response.data;
return response.data.map(function(u) {
u.sortName = u.userName.toLowerCase();
return u; // Это вот забыли
});
});
var myselect = document.getElementById('myselect'),
selIndx = 0;
myselect.addEventListener('focus', function() {
selIndx = this.selectedIndex;
this.options[this.options.length - 1].selected = true;
}, false);
myselect.addEventListener('blur', function() {
this.selectedIndex = selIndx;
}, false);
myselect.addEventListener('change', function() {
selIndx = this.selectedIndex;
this.blur();
}, false);
var sel = document.querySelector('select');
sel.options[0].textContent = 'от ' + sel.options[0].textContent;
sel.addEventListener('change', function(){
var curIndex = this.selectedIndex;
[].forEach.call(this.options,function(opt, i){
if(i === curIndex) {
opt.textContent = 'от ' + opt.textContent;
} else {
opt.textContent = opt.textContent.replace(/[^\d]+/,'');
}
});
});
Или чуть покороче, изменив цикл[].forEach.call(this.options,function(opt, i){
opt.textContent = i === curIndex ? 'от ' + opt.textContent : opt.textContent.replace(/[^\d]+/,'');
});
cloneNode
replaceChild
<div id="inp1"></div>
<div id="inp2"></div>
inp1.parentNode.insertBefore(inp1, inp2);
function replaceElements(elemOne, elemTwo){
var next = elemOne.nextElementSiblings,
parentOne = elemOne.parentNode,
parentTwo = elemTwo.parentNode
;
parentTwo.insertBefore(elemOne, elemTwo);
if(next){
parentOne.insertBefore(elemTwo, next);
}else{
parentOne.appendChild(elemTwo);
}
}
replaceElements(inp1, inp2);
$('#first').insertAfter('#second');
// или аналогично
// $('#second').insertBefore('#first');