что решения не работают так, как хотелось бы .. Я переписываю код и делаю это:
var mmyBox = Backbone.Model.extend({});
var cmyBox = Backbone.Collection.extend({
model: mmyBox,
url: 'http://localhost/wordpress/oferta/prueba1/?json=get_taxonomy&taxonomy=habilidad&dev=1',
parse: function (resp, xhr) {
console.log(resp.terms);
return resp.terms;
}
});
function validateEmail(str) {
var regex = new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
return regex.test(str) ? null : 'Invalid email';
}
var Form = Backbone.Model.extend({
schema: {
id: {},
nombre: {},
apellidos: {},
email: { type: 'Text', dataType: 'email', validators: ['required', validateEmail] },
telefono: { type: 'Text', dataType: 'tel', validators: ['required'] },
nacionalidad: { type: 'Select', options: ['Española', 'Extranjera'] },
link1: { type: 'Text', title: 'Enlace a Reel', dataType: 'url' },
link2: { type: 'Text', title: 'Enlace a Web/Blog', dataType: 'url' },
otros: { type: 'Text', dataType: 'url' },
skills: { type: 'Checkboxes', options: new cmyBox() },
}
});
Функция анализа возвращает элементы массива из json.
Array
{
"status": "ok",
"count": 3,
"terms": [
{
"id": 11,
"slug": "artist",
"title": "artist",
"description": "",
"post_count": 1
},
{
"id": 13,
"slug": "medico",
"title": "medico",
"description": "",
"post_count": 1
},
{
"id": 12,
"slug": "programador",
"title": "programador",
"description": "",
"post_count": 1
}
]
Кажется, что новый cmyBox не создает новую коллекцию. Хорошо, это то, что я вижу на консоли.
Спасибо, Джош, за ответ. Приветствия.