简体   繁体   English

淘汰赛JS模板HTML无法正确渲染

[英]Knockout JS Template HTML Not Rendering Properly

I have a knockout template that was working fine until I made a minor change to it for display purposes. 我有一个剔除模板,可以正常工作,直到我出于显示目的对其进行了较小的更改。 Now the HTML is rendering differently which is causing some of my SCSS to not apply certain styles. 现在HTML呈现的方式有所不同,这导致我的某些SCSS无法应用某些样式。 Here is the current template: 这是当前模板:

<script type="text/html" id="dropDownTextBoxTemplate">
    <div class="top-level-div-class">
        <p class="paragraph-class">
            <div>
                <label data-bind="text: DisplayValue"></label>
            </div>
            <div>
                <select data-bind="attr: { id: Name, name: Name }, options: Comparisons, optionsValue: 'Name', optionsText: 'DisplayValue', optionsCaption: 'Unselected', value: SelectedComparison"></select>
                <!-- ko if: SelectedComparison() === undefined -->
                <input type="text" disabled="disabled" data-bind="attr: { id: Name + '-value', name: Name + '-value', 'data-min-value': TextboxMinValue, 'data-max-value': TextboxMaxValue, 'data-format': TextboxFormat }, value: TextboxValue" />
                <!-- /ko -->
                <!-- ko ifnot: SelectedComparison() === undefined -->
                <input type="text" data-bind="attr: { id: Name + '-value', name: Name + '-value', 'data-min-value': TextboxMinValue, 'data-max-value': TextboxMaxValue, 'data-format': TextboxFormat }, value: TextboxValue" />
                <!-- /ko -->
            </div>
        </p>
    </div>
</script>

The change I made was to add the div tags around the label, select and input controls. 我所做的更改是在标签周围添加div标签,选择和输入控件。 Here is the HTML that is rendered. 这是呈现的HTML。

<div class="top-level-div-class">
    <p class="paragraph-class"></p>
    <div>
        <label data-bind="text: DisplayValue">My Display Value:</label>
    </div>
    <div>
        <select data-bind="attr: { id: Name, name: Name }, options: Comparisons, optionsValue: 'Name', optionsText: 'DisplayValue', optionsCaption: 'Unselected', value: SelectedComparison" id="attendence" name="attendence">
            <option value="">Unselected</option>
            <option value="gtet">Greater than or equal to</option>
            <option value="ltet">Less than or equal to</option>
        </select>
        <!-- ko if: SelectedComparison() === undefined -->
        <input type="text" disabled="disabled" data-bind="attr: { id: Name + '-value', name: Name + '-value', 'data-min-value': TextboxMinValue, 'data-max-value': TextboxMaxValue, 'data-format': TextboxFormat }, value: TextboxValue" id="attendence-value" name="attendence-value" data-min-value="0" data-max-value="99" data-format="range">
        <!-- /ko -->
        <!-- ko ifnot: SelectedComparison() === undefined -->
        <!-- /ko -->
    </div>
    <p></p>
</div>

As you can see the paragraph tag is rendered by itself instead of being around the content as it is in the template. 如您所见,段落标记是由其自身呈现的,而不是像模板中那样围绕内容。 When the extra div's are removed the paragraph tag renders around all of the other content, which is the desired HTML output, but when I do that the UI elements don't align properly. 当删除多余的div时,段落标签会围绕所有其他内容进行渲染,这是所需的HTML输出,但是当我这样做时,UI元素无法正确对齐。 I have tried replacing the extra div's with span tags and the HTML does render properly but once again the UI controls are out of alignment. 我尝试用span标签替换多余的div,HTML可以正确呈现,但UI控件再次未对齐。 Any help would be appreciated. 任何帮助,将不胜感激。

Try using the paragraph tag as div. 尝试将段落标签用作div。 Its not allowed to enclose divs inside paragraph tags. 不允许将div括在段落标签内。

here is the change you should try. 这是您应该尝试的更改。

 <script type="text/html" id="dropDownTextBoxTemplate">
        <div class="top-level-div-class">
            <div class="paragraph-class">
                <div>
                    <label data-bind="text: DisplayValue"></label>
                </div>
                <div>
                    <select data-bind="attr: { id: Name, name: Name }, options: Comparisons, optionsValue: 'Name', optionsText: 'DisplayValue', optionsCaption: 'Unselected', value: SelectedComparison"></select>
                    <!-- ko if: SelectedComparison() === undefined -->
                    <input type="text" disabled="disabled" data-bind="attr: { id: Name + '-value', name: Name + '-value', 'data-min-value': TextboxMinValue, 'data-max-value': TextboxMaxValue, 'data-format': TextboxFormat }, value: TextboxValue" />
                    <!-- /ko -->
                    <!-- ko ifnot: SelectedComparison() === undefined -->
                    <input type="text" data-bind="attr: { id: Name + '-value', name: Name + '-value', 'data-min-value': TextboxMinValue, 'data-max-value': TextboxMaxValue, 'data-format': TextboxFormat }, value: TextboxValue" />
                    <!-- /ko -->
                </div>
            </div>
        </div>
    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM