我有一个具有相同名称的3选择标记,我想只使用backbone.js在一个保存中更新我的表。 在我的表中有3个修复记录:没有添加,只删除更新查询正在使用此代码。
id docs_id
1 5
2 3
3 6
以下是我的HTML代码:
<select name="docs_id" id="docs_id" >
<option value="0"> </option>
</select>
<select name="docs_id" id="docs_id" >
<option value="0"> </option>
</select>
<select name="docs_id" id="docs_id" >
<option value="0"> </option>
</select>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Cancel</a>
<a href="#" class="btn btn-success" id="options-submit">Submit</a>
</div>
在我的目录视图javascript中我有这段代码
events: {
"click .record-set" : "setDocs"
},
setDocs: function (e) {
e.preventDefault();
var that = this;
$('#setDocs').live('show', function () {
$(this).find('.btn-success').die().live('click', function () {
var d = Array;
$.map($('.inopts select').serializeArray(), function(n, i) {
d[n['name']] = n['value'];
});
options2 = new Options2();
options2.save(d, {
success: function (model, response) {
this.$el = $('#setDocs');
this.$el.modal('hide');
alert = new AlertView({type: 'success', message: 'New record successfully added.'});
alert.render();
},
error: function (model, response) {
alert = new AlertView({type: 'error', message: response});
alert.render();
}
});
});
})
.modal();
},
.............
这是我的模型javacript
var Options2 = Backbone.Model.extend({
idAttribute: 'id',
url: function () {
if (this.isNew()) {
return BASE_URL + 'api/document_various';
} else {
return BASE_URL + 'api/document_various/id/' + this.get('id');
}
},
defaults: {
docs_id: '',
}
});
在我的其余API中删除我的代码
private function _document_various_save($db, $mode)
{
$response = array('status' => 'failed', 'message' => '');
$db->docs_id = $this->{$mode}('docs_id');
$id = $db->save();
if ($id) {
$response['id'] = $id;
$response['status'] = 'success';
} else {
$response['message'] = $db->get_validation_errors();
}
return $response;
}