簡體   English   中英

與Ember.Select的奇怪問題

[英]Strange Issue with Ember.Select

我對Ember.Select有一個非常奇怪的問題,我在兩個不同的模板中使用相同的Ember.Select ,並且都有兩個不同的控制器支持。 但我只在一個 Ember.Select中獲得了團隊列表。

工作的第一個地方是:

<script type="text/x-handlebars" data-template-name="twoduser">
        <!-- more Info-->

        <div class="span3 pull-left" id="moreinfo2">
        <div class="row">
            <b>Full Name:</b> {{firstname}} {{lastname}}
            <br/>
            <b>Email:</b> {{email}}
            <br/>
            <b>Address:</b> {{address}}, {{city}}, {{state}}, {{country}}
            <!--<br />
            City: 
            <br/>
            State/Province: 
            <br/>
            Country:
            <br/> -->
            <br/>
            <b>Phone:</b> {{phone}}
            <br/>
            <b>Experience:</b> {{experience}}
            <br/>
            <b>Designation:</b> {{designation}}
            <br>

            {{view Ember.Select
        contentBinding="team"
        optionValuePath="content.team_name"
        optionLabelPath="content.team_name"
        selectionBinding="selectedTeam"
        prompt="Please Select a Team"}}
            <button class="btn" {{action 'addToTeam' }}>Add To Team</button>
        </div>
        </div>
        </script>

對應控制器:

App.TwoduserController = Ember.ObjectController.extend({
    selectedTeam : null,
    team : function (){
        var teams = [];
        $.ajax({
            type : "GET",
            url : "http://pioneerdev.us/users/getTeamNames",
            success : function (data){
                for (var i = 0; i < data.teams.length; i ++){
                    var teamNames = data.teams[i];
                    teams.pushObject(teamNames);
                }
            }
        }); 
        return teams;
    }.property(),
});

第二個不工作的地方

 <script type="text/x-handlebars" id="teammembers">
        <div class="row-fluid">
        <div class="span3 offset3">
            <div class="row-fluid">
                <div class="span12">
                <h4>Your Team Members</h4>
                {{view Ember.Select
                contentBinding="team"
                optionValuePath="content.team_name"
                optionLabelPath="content.team_name"
                selectionBinding="selectedTeam"
                prompt="Please Select a Team"}}
            <ul>
                <li>
                {{#each item in arrangedContent}}
                    {{#link-to 'teammemberdetail' item}}{{item.firstname}}, {{item.team_name}}{{/link-to}}
                    <br>
                {{else}}        
                    <p><b>Nothing there</b></p>        
                {{/each}}
                </li>
            </ul>
                <button class="btn"
                {{action 'generate'}}>Get Team Members PDFs</button>
                </div>
                </div>
                <div class="row">
                    <div class="span12 offset5">{{outlet}}</div>
                </div>
                </div>
            </div>
        </script>

對應控制器:

    App.TeammembersController = Ember.ObjectController.extend({
        selectedTeam : null,
        team : function (){
            var teams = [];

            $.ajax({
                type : "GET",
                url : "http://pioneerdev.us/users/getTeamNames",
                success : function (data){
                    for (var i = 0; i < data.teams.length; i ++){
                        var teamNames = data.teams[i];
                        teams.pushObject(teamNames);
                    }
                }
            }); 
            return teams;
        }.property(),
});

我在后面的名單中得到了名單。 為什么會這樣?

您應該使用Route從后端檢索數據並將其設置在控制器中(查看有關ember路徑的指南)。

那你就不應該有content. optionValueBindingoptionLabelBinding的路徑的一部分。

最后你應該更好地使用Ember的{{select}} Handlebars助手。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM