Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

javascript - 传递调用结果时出现异常:TypeError:不是流星中的函数(Exception in delivering result of invoking : TypeError: is not a function in meteor)

When I added in onSuccessCreateClass into meteor.call callback and this error come up.

(当我将onSuccessCreateClass添加到meteor.call回调中时,出现此错误。)

dont know what is wrong here?

(不知道这是怎么回事?)

Exception in delivering result of invoking 'createClass': TypeError: this.onSuccessCreateClass is not a function at http://localhost:3000/app/client/components/MyClasses.jsx?044c7b228d4b33fcea4b9f3c05da6d82e5e6c8b7:37:11 at null._callback ( http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:22 ) at _.extend._maybeInvokeCallback ( http://localhost:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:3500:12 ) at .extend.dataVisible ( http://localhost:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:3529:10 ) at http://localhost:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:4365:7 at Array.forEach (native) at Function.

(传递调用'createClass'的结果时发生异常:TypeError:this.onSuccessCreateClass不是http:// localhost:3000 / app / client / components / MyClasses.jsx?044c7b228d4b33fcea4b9f3c05da6d82e5e6c8b7:37:11处的函数。_callback( http: //localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:22 )在_.extend._maybeInvokeCallback( HTTP://本地主机:3000 /包/ DDP-client.js 250b63e6c919c5383a0511ee4efbf42bb70a650f:3500:12 )在.extend .dataVisible( http:// localhost:3000 / packages / ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:3529:10 )at http:// localhost:3000 / packages / ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb707 at 600: Array Function的forEach(本机)。)

.each._.forEach ( http://localhost:3000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:149:11 ) at _.extend._runAfterUpdateCallbacks ( http://localhost:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:4364:7 ) at _.extend._livedata_data ( http://localhost:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:4354:10 ) at onMessage ( http://localhost:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:3361:12 )

(.each ._。forEach( http:// localhost:3000 / packages / underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:149:11 )位于_.extend._runAfterUpdateCallbacks( http:// localhost:3000 / packages / ddp-client.js? 250b63e6c919c5383a0511ee4efbf42bb70a650f:4364:7在_.extend._livedata_data)( HTTP://本地主机:3000 /包/ DDP-client.js 250b63e6c919c5383a0511ee4efbf42bb70a650f:4354:10 )在的onMessage( HTTP://本地主机:3000 /包/ ddp- client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:3361:12 ))

onSuccessCreateClass() {
    console.log("Successfully created New Class")
    $("#createClassModal").modal('hide')
    $('#createClassModal').on('hidden.bs.modal', function () {
        $(this).find('form').trigger('reset')
    })
},

onPressSubmit(e) {
    e.preventDefault()
    const className = e.target.cname.value
    console.log(this.props.courseId)
    console.log(className)
    if (Meteor.user().classes.length !== 0)
    {
        console.log("Got Class")
        Meteor.call("createClass", this.props.courseId, className, function(error) {
            if (error)
            {
                console.log(error.reason)
            }
            else
            {
                this.onSuccessCreateClass()
            }
        })
    }
    else
    {
        console.log("No Class")
        Meteor.call("createNewClass", this.props.courseId, className, function(error) {
            if (error)
            {
                console.log(error.reason)
            }
            else
            {
                this.onSuccessCreateClass()
            }
        })
    }
},
  ask by phongyewtong translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should set this for callback in Meteor.call , because now this refers to the global scope or undefined if you are using strict mode .

(您应该设置this在回调Meteor.call ,因为现在this指的是全球范围或undefined ,如果你使用的是strict mode 。)

In JavaScript, there is method .bind which allows set this for method

(在JavaScript中,方法.bind允许为方法设置this值)

Meteor.call("createClass", this.props.courseId, className, function(error) {
   if (error) {
     console.log(error.reason)
   } else {
     this.onSuccessCreateClass()
   }
}.bind(this))

--

(-)

Meteor.call("createNewClass", this.props.courseId, className, function(error) {
  if (error) {
    console.log(error.reason)
  } else {
    this.onSuccessCreateClass()
  }
}.bind(this))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...