gpt4 book ai didi

knockout.js - Knockoutjs 模板 foreach,特别的第一项

转载 作者:行者123 更新时间:2023-12-03 23:09:52 24 4
gpt4 key购买 nike

所以我一直在绞尽脑汁想办法解决这个问题。我有一个 foreach,吐出模板,我希望第一个元素有一个特殊的属性。到目前为止,我发现的解决方案还没有奏效。

这是foreach:

<h3 class="question">Geografi</h3>   
<p class="answer" data-bind="template: { name: 'geographyTmpl', foreach: geographyList, templateOptions: { selections: selectedGeographies } }"></p>

这是模板:
<script id="geographyTmpl" type="text/html">
<input class="geoCheckList" validate="required:true, minlength:2" name="geoCheckList[]" type="checkbox" data-bind='value: $data, attr: { id: "Geo"+$index()},checked: $root.selectedGeographies' />
<label data-bind="text: $data, attr: { 'for': 'Geo'+$index()}"></label>

我想添加: "validate="required:true, minlength:2"到第一个元素。

我需要做什么?

如果有帮助,则用于 jQuery 验证。

最佳答案

检查我对 KnockoutJS 中第一个元素的另一个问题的回答 foreach
Skip item in foreach knockout js array?

<div data-bind="text: ItemsArray[0].someProperty"></div>
<div data-bind="foreach: ItemsArray">
<!-- ko if: $index() == 0 -->
<div data-bind="text: someProperty"></div>
<!-- /ko -->
<!-- ko if: $index() != 0 -->
<div data-bind="text: anotherDifferentProperty"></div>
<!-- /ko -->
</div>

关于knockout.js - Knockoutjs 模板 foreach,特别的第一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15340145/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com