Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm able to use jquey.tmpl syntax inside script tag and bind it to knockout template as below:

HTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>JQuery templ Binding Demo</title>
    <script src="../../Scripts/jquery-2.1.1.min.js"></script>
    <script src="../../Scripts/jquery.tmpl.min.js"></script>
    <script src="../../Scripts/knockout-3.2.0.js"></script>
    <script>
        $(document).ready(function () {
            function myViewModel() {
                var self = this;
                self.employees = [{name:'Sudheer',age:24}, {name:'Sumanth',age:25}];
            };

            ko.applyBindings(new myViewModel());
        });
    </script>
</head>
<body>
    <div data-bind="template:'my-Template'"></div>
    <script type="text/html" id="my-Template">
        {{each employees}}
        <p>Name: ${name}</p>
        <p>Age : ${age}</p>
        {{/each}}
    </script>
</body>
</html>


But when i use jquery.tmpl syntax inside component registration template field as below:
HTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Component Registration Demo</title>
    <script src="../../Scripts/jquery-2.1.1.min.js"></script>
    <script src="../../Scripts/jquery.tmpl.min.js"></script>
    <script src="../../Scripts/knockout-3.2.0.js"></script>
    <script>
        $(document).ready(function () {
            ko.components.register('name-widget', {
                viewModel: function (params) {
                    this.employeeModel = params.value;
                    this.employeeName = this.employeeModel.name;
                },

                template: "<p><span>${employeeName}</span></p>"
            });

            function employeeInfoViewModel() {
                this.employee = {name:'Sudheer',age:24};
            };

            ko.applyBindings(new employeeInfoViewModel());
        });
    </script>
</head>
<body>
        <p><name-widget params="value: employee"></name-widget></p>
</body>
</html>


It is displayed as ${employeeName} instead of sudheer.

Any info on how to use jquery.tmpl inside component template field?
Posted
Updated 6-Dec-14 19:32pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900