简体   繁体   中英

Backbone.js: Get the previous value when a change event is triggered

I have registered a method on a 'change' event for a dropdown list as follows:

this.$el_period.on('change', function () {that.my_method();});

In my_method, I can get the new value that was selected but I would like to know if it is possible to get the previous value from which the user switched.

Thank's

Yes. That is possible to get previous state.

From the documentation:

var bill = new Backbone.Model({
name: "Bill Smith"
});

bill.on("change:name", function(model, name) {
    alert("Changed name from " + bill.previous("name") + " to " + name);
});

bill.set({name : "Bill Jones"});

Docs: https://backbonejs.org/#Model-previous

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM