我正在尝试格式化包含具有两个子对象的对象的爆震模型。当我尝试为子对象包含标题时,第二个结束于我期望的组之外。如果编码或我的期望存在问题,请告诉我。
期望:
标题 PROP1 PROP2 List1标题 List1 Item1 List1 Item2 List2标题 清单2项目1 清单2第2项
我得到了什么:
标题 PROP1 PROP2 List1标题 List1 Item1 List1 Item2
清单2项目1 清单2第2项
List2标题
代码是:
<div id="tourneys_in_progress">
<h2>Open Tournaments</h2>
<div id="tourneys">
<ul data-bind="template: { name: 'tourneyTemplate', foreach: tourneys.CurrentTournaments }"></ul>
<script id="tourneyTemplate" type="text/html">
<li class="tourneys">
<div class="tourney">
<div data-bind="text: 'TournamentType: ' + TournamentTypeString"></div>
<div data-bind="text: 'Number of Rounds: ' + Rounds" ></div>
<div data-bind="text: 'Boards: ' + Boards" ></div>
<div data-bind="text: 'Players per Board: ' + PlayersPerBoard"></div>
<div data-bind="text: 'Time Control: ' + TimeControlString"></div>
<div data-bind="attr: { title: TournamentId }" class="join_tourney command">Cancel Tournament</div>
<div data-bind="attr: { title: TournamentId }" class="leave_tourney command">Start Round</div>
<div data-bind="attr: { title: TournamentId }" class="leave_tourney command">End Round</div>
<div>
<ul data-bind="template: { name: 'gamesTemplate', foreach: TournamentGames }"></ul>
<ul data-bind="template: { name: 'playersTemplate', foreach: TournamentPlayers }"></ul>
<h3>Current Tournament Games</h3>
<script id="gamesTemplate" type="text/html">
<li class="players">
<div class="left_align" data-bind="text: 'Tournament Players: ' + TournamentPlayersList + ' '"/>
<div class="right_align" data-bind="text: GameStatusText" />
<div class="command">Set Game</div>
</li>
</script>
<h3>Current Tournament Players</h3>
<script id="playersTemplate" type="text/html">
<li class="players">
<span class="left_align" data-bind="text: PlayerName + ' '"/>
<img data-bind="attr: { src: 'https://graph.facebook.com/' + FbId + '/picture?width=25&height=25' }" />
<span class="right_align" data-bind="text: PlayerRanking" />
</li>
</script>
</div>
</li>
</script>
</div>
</div>
感谢您的帮助。
答案 0 :(得分:1)
我能够通过以下html标记获得我想要的格式:
<div id="tourneys_in_progress">
<h2>Open Tournaments</h2>
<div id="tourneys">
<ul data-bind="template: { name: 'tourneyTemplate', foreach: tourneys.CurrentTournaments }"></ul>
<script id="tourneyTemplate" type="text/html">
<li class="tourneys">
<div class="tourney">
<div data-bind="text: 'TournamentType: ' + TournamentTypeString"></div>
<div data-bind="text: 'Number of Rounds: ' + Rounds" ></div>
<div data-bind="text: 'Boards: ' + Boards" ></div>
<div data-bind="text: 'Players per Board: ' + PlayersPerBoard"></div>
<div data-bind="text: 'Time Control: ' + TimeControlString"></div>
<div data-bind="attr: { title: TournamentId }" class="join_tourney command">Cancel Tournament</div>
<div data-bind="attr: { title: TournamentId }" class="leave_tourney command">Start Round</div>
<div data-bind="attr: { title: TournamentId }" class="leave_tourney command">End Round</div>
<div>
<h3>Current Tournament Games</h3>
<ul data-bind="template: { name: 'gamesTemplate', foreach: TournamentGames }"></ul>
<h3>Current Tournament Players</h3>
<ul data-bind="template: { name: 'playersTemplate', foreach: TournamentPlayers }"></ul>
<script id="gamesTemplate" type="text/html">
<li class="players">
<p class="left_align" data-bind="text: 'Tournament Players: ' + TournamentPlayersList + ' '"></p>
<p class="right_align" data-bind="text: GameStatusText"></p>
<div class="command">Set Game</div>
</li>
</script>
<script id="playersTemplate" type="text/html">
<li class="players">
<span class="left_align" data-bind="text: PlayerName + ' '"/>
<img data-bind="attr: { src: 'https://graph.facebook.com/' + FbId + '/picture?width=25&height=25' }" />
<span class="right_align" data-bind="text: PlayerRanking" />
</li>
</script>
</div>
</div>
</li>
</script>
</div>
</div>
感谢您的投入。