Ember數據只是不會將參數追加到查詢中。我有這樣Ember數據不會將參數附加到查詢中
例如
App.TagsRoute = Ember.Route.extend({
model: function(params) {
var tag = params.tag_name;
var entries = this.store.find('entry', {tags: tag});
return entries;
}
});
一個標籤的路線,但這樣下去使得作爲this.store.find相同的請求(「入口」)。 我做錯了嗎?
編輯:
我的路由器看起來像這樣:
App.Router.map(function(){
this.resource('entries', function(){
this.resource('entry', { path: '/entry/:entry_id/:entry_title' });
});
this.route('tags', { path: '/t/:tag_name' });
});
當我請求(例如)本地主機:8888 /#/噸/標籤
params.tag_name的值是'標籤'
EDIT2:
我的REST接口
App.ApplicationAdapter = DS.RESTAdapter.extend({
bulkCommit: false,
buildURL: function(record, suffix) {
var s = this._super(record, suffix);
return s + ".json";
},
findQuery: function(store, type, query) {
var url = this.buildURL(type.typeKey),
proc = 'GET',
obj = { data: query },
theFinalQuery = url + "?" + $.param(query);
console.log(url); // this is the base url
console.log(proc); // this is the procedure
console.log(obj); // an object sent down to attach to the ajax request
console.log(theFinalQuery); // what the query looks like
// use the default rest adapter implementation
return this._super(store, type, query);
}
});
EDIT3:
作出一些改變,以我的TagsRoute對象我得到一個輸出:
App.TagsRoute = Ember.Route.extend({
model: function(params) {
var tag = params.tag_name;
var query = {tags: tag};
console.log(query);
var entries = this.store.find('entry', query);
return entries;
}
});
控制檯輸出,當我要求本地主機: 8888 /#/ t/tag
對象{標籤: 「標籤」}
(主機URL)+ API/V1/entries.json
GET
對象{數據:對象}
(主機URL)+ API/V1/entries.json?標記=標記
類{type:function,query:Object,store:Class,isLoaded:true,meta:Object ...}
Ember數據附加GET參數。我想我的錯誤,也許是請求的網址,它應該是這樣的
(主機URL)+ API/V1 /標籤/:tag_name.json
而不是
(主機URL)+ API/V1 /entries.json?tags=:tag_name
SOLUTION
餘燼數據(餘燼數據1.0.0-beta.3-16-g2205566)的構建被打破。當我將腳本src更改爲builds.emberjs.com.s3.amazonaws.com/canary/daily/20131018/ember-data.js時,一切都很完美。
適當的方法來添加GET參數是:
var query = {param: value};
var array = this.store.find('model', query);
感謝您的幫助
發送的請求是什麼? – Kingpin2k
我編輯了問題@daniel – cmszc