JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div data-bind="template: { foreach: myItems, name: 'template-item' }" class="span8" style="border-bottom: 1px solid #0094ff;"></div>
<!-- basic template -->
<script type="text/html" id="template-item">
<div data-bind="text: hotelId"></div>
<div data-bind="text: hotelName"></div>
<div data-bind="text: hotelRating"></div>
<div data-bind="text: propertyCategory"></div>
<a data-bind="KoYourCustomBind: $data" href="#">link</a>
<div style="height:10px;"> </div>
</script>
JavaScript
// sample viewModel
var testViewModel = function(){
var self = this;
// another viewmodel property you want to use in url creation.
this.urlPart = "/ALLUSE/";
// array or list is called myItems
var iData = [new myItem("999", "Sheraton", "CAT7"), new myItem("007", "Marriott", "CAT11"), new myItem("212", "Budget Inn", "CAT00")];
this.myItems = ko.observableArray(iData);
}
var myItem = function(sHotelId, sName, sPropertyCategory) {
var self = this;
this.hotelId = sHotelId;
this.hotelName = sName;
this.hotelRating = 4; //hardcoded. only 4 star hotels here :)
this.propertyCategory = sPropertyCategory;
};
// ko bindings
ko.bindingHandlers.KoYourCustomBind = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)
{
var item = valueAccessor();
var url = 'http://' + bindingContext.$parent.urlPart + item.hotelId + item.propertyCategory + '/' + item.hotelName;
$(element).text(item.hotelName);
$(element).attr('href', url);
}
};
var vm = new testViewModel();
ko.applyBindings(vm);