12 Temmuz 2011, Salı
Backbone.js parametreleri ile getir
documentation, benim yaptığımı yapın:
var collection = new Backbone.Collection.extend({
model: ItemModel,
url: '/Items'
})
collection.fetch({ data: { page: 1} });
url olduğu ortaya çıktı: http://localhost:1273/Items?[object Object]
http://localhost:1273/Items?page=1
gibi bir şey bekliyordum
Nasıl pas içinde kullanımı yöntem getirme, ne yapmalıyım?
CEVAP
12 Temmuz 2011, Salı
değiştirme:
collection.fetch({ data: { page: 1} });
için:
collection.fetch({ data: $.param({ page: 1}) });
Bu işin içinde olan, bu options
{data: {page:1}}
nesnesi olarak adlandırılır
Backbone.sync = function(method, model, options) {
var type = methodMap[method];
// Default JSON-request options.
var params = _.extend({
type: type,
dataType: 'json',
processData: false
}, options);
// Ensure that we have a URL.
if (!params.url) {
params.url = getUrl(model) || urlError();
}
// Ensure that we have the appropriate request data.
if (!params.data && model && (method == 'create' || method == 'update')) {
params.contentType = 'application/json';
params.data = JSON.stringify(model.toJSON());
}
// For older servers, emulate JSON by encoding the request into an HTML-form.
if (Backbone.emulateJSON) {
params.contentType = 'application/x-www-form-urlencoded';
params.processData = true;
params.data = params.data ? {model : params.data} : {};
}
// For older servers, emulate HTTP by mimicking the HTTP method with `_method`
// And an `X-HTTP-Method-Override` header.
if (Backbone.emulateHTTP) {
if (type === 'PUT' || type === 'DELETE') {
if (Backbone.emulateJSON) params.data._method = type;
params.type = 'POST';
params.beforeSend = function(xhr) {
xhr.setRequestHeader('X-HTTP-Method-Override', type);
};
}
}
// Make the request.
return $.ajax(params);
};
'Veri params.data
ne olursa olsun eklemek için elinden geleni yapacak olan' URL. jQuery.ajax gönderir
Bunu Paylaş:
Olayları getir çağırırken tetiklenir) ...
bir görünüm parametreleri geçirmek içi...
Nasıl bir web sayfası üzerinden bir PH...
bağlam parametreleri geçirmek için nas...
Nasıl bir toplu iş dosyası komut satır...