我有一张可编辑的表格。下面是一个函数,它给出表,给定要呈现表的元素ID,列数组和控制器名称,用于构造URL。 URL具有以下格式,其中exampleController是示例控制器:
我希望POST请求包含已编辑的信息以及相应的行。
我尝试在下面的代码中做某事。它发出请求但不包括POST。
var initiateGrid = function(element_id, columns, controllerName) {
var gridModel = Backbone.Model.extend({
initialize: function() {
Backbone.Model.prototype.initialize.apply(this, arguments);
this.on("change", function(model, options) {
if (options && options.save === false) {
return;
}
this.sync();
});
},
sync: function(method, model, options) {
var methodUpdateMethodUrl = 'php/gateway.php?sender=' + controllerName + '&action=update';
options = options || {};
options.url = methodUpdateMethodUrl;
Backbone.sync(method, model, options);
}
});
var gridCollectionModel = Backbone.Collection.extend({
model: gridModel,
url: 'php/gateway.php?sender=' + controllerName + '&action=list',
});
var gridCollection = new gridCollectionModel();
var grid = new Backgrid.Grid({
columns: columns,
collection: gridCollection,
emptyText: "No Data"
});
var gridContainer = $("#" + element_id);
gridContainer.append(grid.render().el);
gridCollection.fetch({
reset: true
});
};
当然,还有这个错误:
未捕获的TypeError:无法读取未定义的属性“触发器”
答案 0 :(得分:0)
尝试更改网址
url:function() {
return 'php/gateway.php?sender=' + controllerName + '&action=list',
}
答案 1 :(得分:0)
以下代码对我有用:
set @site := 1 ;
set @language := 3 ;
select
language_id,paragraph_0 from (
select language_id,paragraph_0 from tablename where site_id =@site and language_id = @language
union
select language_id,paragraph_0 from tablename where site_id =@site and language_id = 2
union
select language_id,paragraph_0 from tablename where site_id =@site and language_id = 1
)x
order by language_id desc limit 1;
用PHP获取数组:
var initiateGrid = function(element_id, columns, controllerName) {
var gridModel = Backbone.Model.extend({
initialize: function() {
Backbone.Model.prototype.initialize.apply(this, arguments);
this.on("change", function(model, options) {
this.sync("update", model, options);
});
},
sync: function(method, model, options) {
var methodUrl = {
'update': 'php/gateway.php?sender=' + controllerName + '&action=update'
};
console.log(method, model, options);
if (methodUrl && methodUrl[method.toLowerCase()]) {
options = options || {};
options.url = methodUrl[method.toLowerCase()];
}
Backbone.sync(method, model, options);
}
});
var gridCollectionModel = Backbone.Collection.extend({
model: gridModel,
url: 'php/gateway.php?sender=' + controllerName + '&action=list',
});
var gridCollection = new gridCollectionModel();
var grid = new Backgrid.Grid({
columns: columns,
collection: gridCollection,
emptyText: "No Data"
});
var gridContainer = $("#" + element_id);
gridContainer.append(grid.render().el);
gridCollection.fetch({
reset: true
});
};