S
S
Stepan2014-08-10 13:42:54
JavaScript
Stepan, 2014-08-10 13:42:54

How to get the value of the name attribute?

var NewUserView =Backbone.View.extend({
    initialize: function() {
        this.model = new NewUserModel();
        console.log ('hello');
    },
    el: 'body',
    events: {
        "focusout .textField" : "setValue"
    },
    setValue: function(){
        _.each(this.el, function(){

            if (this.attr('name') == this.model.attributes('attrName')) {
                this.model.set({'attrName':'.val()'})
            }

        }, this)
    }
});

var userView = new NewUserView();

There is such a code, on clicking when the focus is removed from the input, if the name matches the name from the default model, take val () inputa and replace it in the model, but the code does not work help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2014-08-10
@k12th

Strange code. Why do _.each on a DOM element? Why are you accessing model attributes directly?

var input = $(evt.target);
if (input.attr('name') === this.model.get('attrName')) {
    this.model.set('attrName', input.val())
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question