函数返回[Object Object]而不是值
Function return [Object Object] not the value
我创建了这个函数,我不知道为什么它返回[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;
});
相关文章:
- 为什么我得到的是返回的[object HTML ParagraphElement]而不是我的号码
- javascript对象显示为null,但object.properties返回数据
- 将ActiveXObject返回值转换为JQuery Object以处理XML
- 在 Reactjs 中返回 [Object object] 而不是 Dom 字符串
- 为什么jQuery.cookie插件返回“[object object]”
- 控制台返回[Object-Object]而不是对象成员
- 当chrome检查器为jQuery变量返回[object object]时,如何返回实际数据
- Object.defineProperty获取集返回错误的值
- 使用javascript时返回[object HTMLDivElement]
- 为什么lodash中的_.pick(object,_.identity)返回空object
- jQuery的返回值是Array,但构造函数是Object.如何
- 'canvas.getContext('2d')' 返回 'Object'
- Javascript object.id 元素数组中返回“undefined”
- Object.keys(obj).length 返回字符总和而不是记录总数
- 给定一个对象数组,创建一个函数,该函数返回一个 Object,该 Object 具有按类型分组的路径数组
- JSON字符串仍然返回JS中的[object object]
- 使用 Object.asassign 正确返回嵌套状态
- jQuery AJAX 调用返回 [object Object]
- 从Object返回唯一键列表的正确方法
- JSON在控制台日志中作为[object object]返回