javascript - 函数返回 [Object Object] 不是值

标签 javascript jquery function odoo

我创建了这个函数,但我不知道为什么它返回 [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/

相关文章:

javascript - YouTube 播放器 API : retrieving a reference to an existing player

javascript - data-dojo-props中正则表达式的格式是什么?

javascript - JSON 对象(循环查询数据)不返回数据,但显示找到记录

函数返回一个包含来自 Access 的信息的集合,但调用子程序无法读取该集合的元素

javascript - 动态加载 css 方法

javascript - jQuery 的each、查找和追加

javascript - 如何检查 jquery 元素是否为 `del` 标记?

javascript - 克隆时的问题 - jquery

r - 创建一个无需字符串引号即可创建向量的函数

c++ - 我可以在程序中定义的函数上使用 execvp() 吗?