我创建了这个函数,但我不知道为什么它返回 [Object Object]
而不是我得到的值。该函数应返回类似 (Main/121)
的字符串。但是,警报显示了我想要的值。
module.Order = Backbone.Model.extend({
initialize: function (attributes) {
Backbone.Model.prototype.initialize.apply(this, arguments);
this.pos = attributes.pos;
var that = this;
this.sequence_number = this.pos.pos_session.sequence_number++;
debugger;
this.uid = this.generateUniqueId();
this.pro = this.get_the_other_main();
this.set({
creationDate: new Date(),
orderLines: new module.OrderlineCollection(),
paymentLines: new module.PaymentlineCollection(),
name: _t("Order ") + this.uid,
client: null,
sales_person: null,
sales_person_name: null,
new_id: this.pro
});
this.selected_orderline = undefined;
this.selected_paymentline = undefined;
this.screen_data = {}; // see ScreenSelector
this.receipt_type = 'receipt'; // 'receipt' || 'invoice'
this.temporary = attributes.temporary || false;
return this;
},
get_the_other_main: function (callback) {
return new instance.web.Model("pos.order").call('get_the_product', []).done(
function(results) {
var result = results.toString().split(',');
var stringsl=result[1];
var thenum = stringsl.replace( /^\D+/g, '');
var sasa=parseInt(thenum,10)+1
var zika=('00' + sasa).slice(-4)
var the_str=result[1].slice(0,-4).toString();
var new_seq_sasa=the_str+zika
alert(new_seq_sasa)
return callback(new_seq_sasa);
}
);
},
最佳答案
您应该使用 callback
参数并更改调用函数的方式:
get_the_other_main: function (callback) {
return new instance.web.Model("pos.order").call('get_the_product', []).done(
function(results) {
var result = results.toString().split(',');
var stringsl=result[1];
var thenum = stringsl.replace( /^\D+/g, '');
var sasa=parseInt(thenum,10)+1
var zika=('00' + sasa).slice(-4)
var the_str=result[1].slice(0,-4).toString();
var new_seq_sasa=the_str+zika
alert(new_seq_sasa)
return callback(new_seq_sasa);
}
);
},
代替:
this.pro = this.get_the_other_main();
使用(我根据评论重构了你的代码):
var that = this;
this.get_the_other_main(function (result) {
that.pro = result;
});
关于javascript - 函数返回 [Object Object] 不是值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33523026/