我创建了这个函数,我不知道它为什么返回[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);
}
);
},
答案 0 :(得分:2)
您应该使用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;
});