0

我正在尝试格式化包含具有两个子对象的对象的爆震模型。当我尝试包含子对象的标头时,第二个标头最终超出了我期望的组。如果编码或我的期望有问题,请告诉我。

期待:

标题 道具 1 道具 2 列表 1 标题 列表 1 项目 1 列表 1 项目 2 列表 2 标题 列表 2 项目 1 列表 2 项目 2

我得到什么:

标题 道具 1 道具 2 列表 1 标题 列表 1 项目 1 列表 1 项目 2

清单 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>

谢谢你的帮助。

4

1 回答 1

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>

感谢您的输入。

于 2013-07-01T19:10:54.517 回答