Created
November 15, 2017 00:46
-
-
Save lolocoo/58689832a27466f2b9df756529bb4fdb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var list = [ | |
'Cras justo odio', | |
'Dapibus ac facilisis in', | |
'Morbi leo risus', | |
'Porta ac consectetur ac', | |
'Vestibulum at eros' | |
] | |
var list_set = function () { | |
list.push('Item '+ new Date().getTime()); | |
$('#list').trigger('update:list'); | |
}; | |
var list_minus = function () { | |
list.pop(); | |
$('#list').trigger('update:list'); | |
}; | |
$(function(){ | |
var $list = $('#list'); | |
var tpl_fragment = [ | |
'<% _.each(data, function(item){ %>', | |
'<li class="list-group-item"><%= item %></li>', | |
'<% }) %>' | |
].join(''); | |
var list_tpl = _.template(tpl_fragment) | |
$('#list').on('update:list', function(){ | |
$('#list').html(list_tpl({data:list})) | |
}); | |
$('#add').on('click', function(){ | |
list_set() | |
}); | |
$('#minus').on('click', function(){ | |
list_minus() | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment