1

我有一个同名的 3 选择标签,我想只使用主干.js 一次保存更新我的表。在我的表中有 3 个修复记录:没有添加,删除只有更新查询在此代码中使用。

id   docs_id
 1      5
 2      3
 3      6

这是我的html代码:

<select name="docs_id" id="docs_id"  >
       <option value="0">&nbsp;</option>
</select>  
<select name="docs_id" id="docs_id"  >
       <option value="0">&nbsp;</option>
</select>   
<select name="docs_id" id="docs_id"  >
       <option value="0">&nbsp;</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;
}
4

0 回答 0