0

我正在使用淘汰赛外部模板 https://github.com/ifandelse/Knockout.js-External-Template-Engine

但是如何从外部模板中清除新绑定的值和文本。我的html代码是这样的

HTML

<ul data-bind="template: { name: 'RegistrationForm.html' }"></ul>
 <div data-bind="click:Add"></div>    

脚本 当我单击添加时,“RegistrationForm.html”中的表单值将绑定到网格,但同时我需要清除“RegistrationForm.html”中的所有绑定值。假设我在所选模板上有很多字段和一些文本绑定。所以我的问题是如何在单击按钮时从模板中清除绑定文本和表单值。

实际情况:

当打开用户模板时,与相应用户相关的值和文本将绑定到该模板。但是当我单击没有任何值的下一个用户时,第一个用户 vale 仍然存在。我为所有用户使用一个模板)

谢谢

编辑 我的代码喜欢这个结构

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title>Templates</title>
        <style>
            .clear {
                clear: both;
            }
        </style>
        <script type="text/javascript" src="lib/jquery-1.11.2.min.js"></script>
        <script type="text/javascript" src="lib/knockout-3.3.0.js"></script>
        <script type="text/javascript" src="lib/koExternalTemplateEngine_all.js"></script>
        <script>
                    $(function(){
                    function pop1(data)
                    {
                    this.a = ko.obeservable(data.a || '');
                            this.b = ko.obeservable(data.b || '');
                    }
                    function pop2(data)
                    {
                    this.c = ko.obeservable(data.c || '');
                            this.d = ko.obeservable(data.d || '');
                    }
                    Viewmodel = function(){
                    self = this;
                            self.obj = new Object();
                            self.name = {
                            id:1
                                    name:'test'
                            };
                            self.types = [
                            {
                            id:1
                                    name:'test'
                            },
                            {
                            id:2
                                    name:'test2'
                            }

                            ];
                            self.whichPopup = fucntion(){
                    switch (name()){
                    case '1':
                            //Load Template for this option
                            //This wil b a user form with some value will bind when on laod
                            var data {}; // data with a and b
                            self.obj = new pop1(data);
                            break;
                            case '2':
                            //Load Template for this option
                            var data {}; // data with c and d
                            self.obj = new pop1(data);
                            break;
                    }
                    };
                    };
                    }); </script>
    </head>
    <body>
        <div class="Temp">
            <div class="temp1">  
                <div data-bind="template:{name : 'Template1.html'}"></div>  
            </div>
            <div class="clear"></div>
            <div class="temp2">                 
                <div data-bind="template:{name : 'Template2.html'}"></div>              
            </div>  
            <div class="clear"></div>
            <select class="submission_type"
                    data-bind="options: types,
                                   optionsText : 'name',                               
                                   value: name,
                                   optionsCaption:'---Select---'
                    ">
            </select>
            <div data-bind="template:{name : whichPopup}"></div>
            <!--  This part working -->
            <!--
             Table here
             i need to add multiple entried here,
            so will add users here

             1- Select type
             2- Tempalte will opened in a popup
             3- Save to,then dispaly to the grid
            -->


            <!--
              1- Selcted option type that i hav already added before for to add same type but diffrent user
              2- popup1 will opened
              3- but it have the values that i have first time added
              4- if it was text box only then i can clear but it have some text binding to a div too
            -->
        </div>  

    </body>
</html>

更新 我已经改变了概念,让我知道如何在淘汰赛外部模板中禁用缓存模板。到目前为止,我已经尝试过:

infuser.defaults.ajax.cache = false

但不工作,我只需要刷新模板。谢谢

4

0 回答 0