讓我解釋我的問題,我試圖直接從數據庫填充Ember.Select
。直接從數據庫填充Ember.Select
我有這些路線:
this.resource('twod', function() {
this.resource('twoduser', {
path : ':user_id'
});
});
在twoduser
,我顯示關於單個用戶的全部信息。在這個視圖中,我也有一個選擇框,最終用戶將選擇一個按鈕,然後用一個按鈕,他可以將用戶添加到他從Ember.Select中選擇的團隊。
我試圖做到這一點,
App.TwoduserController = Ember.ArrayController.extend({
selectedTeam : null,
team : function(){
var teams = [];
$.ajax({
type : "GET",
url : "http://pioneerdev.us/users/getTeamNames",
data : data,
success : function (data){
for (var i = 0; i < data.length; i ++){
var teamNames = data[i];
teams.push(teamNames);
}
}
});
return teams;
}.property()
})
在
然後我index.html
:
{{view Ember.Select
contentBinding="team"
optionValuePath="teams.team_name"
optionLabelPath="teams.team_name"
selectionBinding="selectedTeam"
prompt="Please Select a Team"}}
但我這樣做的時候,由於某種原因,它會干擾Twoduser
,我無法查看單個用戶。
此外,這裏有一個樣本JSON
迴應,我將通過網址獲得:
{"teams":[{"team_name":"Toronto Maple Leafs"},{"team_name":"Vancouver Canuck"}]}
此外,我使用獲取所有用戶的Ajax這樣的:
App.Twod.reopenClass({
findAll : function() {
return new Ember.RSVP.Promise(function(resolve, reject) {
$.getJSON("http://pioneerdev.us/users/index", function(data) {
var result = data.users.map(function(row) {
return App.Twod.create(row);
});
resolve(result);
}).fail(reject);
});
},
findBy : function(user_id) {
return new Ember.RSVP.Promise(function(resolve, reject) {
var user = App.Twod.create();
$.getJSON("http://pioneerdev.us/users/byId/" + user_id, function(data) {
var result = user.setProperties(data.user);
resolve(result);
}).fail(reject);
});
}
});
雖然有一件事,我有一個單獨的Teams
路線:
this.resource('teamview', function(){
this.resource('teamviewdetail', {
path : ':team_id'
});
});
當您單擊一個團隊時,它會顯示所有團隊和一個團隊。
我可以使用TeamviewController
嗎?或者我可以從Twoduser
控制器中獲取團隊名稱,並像前面提到的那樣將名稱推送到數組中?
更多信息:
如果我用我提到的方式,我得到這個錯誤:
Uncaught TypeError: Object [object Object] has no method 'addArrayObserver'
這裏有一個工作的問題jsfiddle我遇到。您可以從名稱&中選擇「Storyboard」,然後選擇該用戶。這將重現這個問題。
多一個更新:似乎使用ObjectController
而不是ArrayController
問題解決了addArrayObserver問題。但是我仍然無法讓Ember.Select中的球隊進入。
App.TwoduserController.team需要'返回球隊;'線 –
如果我用這個方法,我得到的錯誤,遺漏的類型錯誤:對象的翻譯:有沒有方法「addArrayObserver」 – user1601973