1
Я пытаюсь принести одну модель и набор моделей mockjax (jsfiddle):Backbone.js + JQuery-mockjax: принести обработчик успеха не работает
var Person = Backbone.Model.extend({ urlRoot: "/person" }),
person,
People = Backbone.Collection.extend({ url: "/people", model: Person }),
people;
// Fetching a single model
$.mockjax({
url: "/person/*",
responseText: { id: 1, name: "Ann", age: 10 }
});
person = new Person({ id: 1 });
person.fetch({
success: function() {
console.log(person.get("name"));
}
});
$.mockjaxClear();
// Fetching a collection of models
$.mockjax({
url: '/people',
responseText: [
{ id: 1, name: "Ann", age: 10 },
{ id: 2, name: "Bill", age: 20 }
]
});
var people = new People();
people.fetch({
success: function() {
console.log(people.length);
}
});
$.mockjaxClear();
На консоли вывода показывает, что mockjax получил запрос GET, но обработчики успеха не были вызваны:
MOCK GET: /person/1
MOCK GET: /people
Почему мои обработчики успеха не звонил?