[英]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.
optionValueBinding
和optionLabelBinding
的路徑的一部分。
最后你應該更好地使用Ember的{{select}}
Handlebars助手。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.