Ember.Select的奇怪问题

Strange Issue with Ember.Select

本文关键字:问题 Select Ember      更新时间:2023-10-24

我对Ember有一个非常奇怪的问题。选择,我在两个不同的模板中使用相同的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从后端检索数据,并在控制器中进行设置(请参阅有关成员路由的指南)。

那么在optionValueBindingoptionLabelBinding中不应该有路径的content.部分。

最后,您应该更好地使用Ember中的{{select}} Handlebars辅助对象。