我正在尝试使用 jQuery.select2 插件。它是用 Backbone.js 和 RequireJS 编写的表单的一部分。我正在编写它的查询/搜索功能,但我遇到了某种我找不到的解析错误。
视图的代码是:
define([
'backbone',
'jquery.select2'
],
function(Backbone, Select2) {
var notificationSelector = Backbone.View.extend({
notifications: undefined,
// events:
// {
// // type letter into box EVENT --> filter populated email list
// },
initialize: function(attrs) {
this.collection.on('add remove reset', this.render(), this);
/* select2 Event s.t. call "select2ContactsChanged" ? */
},
/*
<><><><><><><><>
Getting a syntax / parseerror in the AJAX call below?
What am I missing?
*/
render: function() {
/* DEVELOPMENT SETUP */
// plucking by "caption" will need to be changed...
if(this.select2Control == undefined)
{
// Do Search() + query here
// this.select2Control = this.$el.val(this.collection.pluck('caption').join(' ')).select2({
this.select2Control = this.$el.select2({
width: '200px',
placeholder: '@email',
tags: [],
minimumInputLength: 3,
query: function() {
$.ajax({
url: "/notifications/search",
dataType: 'json',
type: 'GET',
//data: { },
success: function(data) {
/* DEBUG */
console.log('AJAX Success!');
console.log(data);
},
error: function(jqXHR, status, error) {
/* DEBUG */
console.log('<Failure>');
console.log(jqXHR);
console.log('-------------------------');
console.log(status);
console.log('-------------------------');
console.log(error);
}
});
} // END-OF query: function()
});
}
else
{
// Go off of what's currently in the Collection and re-render
}
// this.$el.select2('data', this.model);
},
select2ContactsChanged: function() {
// when this gets called update this.collection to reflect the this.select2Control's val()
this.collection.reset(this.select2Control.val().split(' '));
}
});
return notificationSelector;
});
错误回调告诉我有一个 parseerror /syntax 错误(我正在使用 Chrome 的 Web Inspector 的网络部分),但我似乎找不到它。任何人都可以看到我缺少什么或为什么我可能会收到该错误吗?
谢谢你的时间!