Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 坚持使用getJson.then()函数和this.store.find_Jquery_Ember.js - Fatal编程技术网

Jquery 坚持使用getJson.then()函数和this.store.find

Jquery 坚持使用getJson.then()函数和this.store.find,jquery,ember.js,Jquery,Ember.js,我有以下应用程序控制器: App.ApplicationController = Ember.Controller.extend({ // the initial value of the `search` property query: '', actions: { searchQuery: function () { // the current value of the text field var

我有以下应用程序控制器:

App.ApplicationController = Ember.Controller.extend({
    // the initial value of the `search` property
    query: '',

    actions: {
        searchQuery: function () {
            // the current value of the text field
            var query = this.get('search');

            // numeric search
            if (parseInt(query) > 0) {
                this.transitionToRoute('article', this.store.find('article', query)); // works
            }
            // string search
            else {
                // search database for the search keyword
                jQuery.getJSON("/search/article/" + query + "").then(function(response){
                    if(parseInt(response.id) > 0){
                        console.log(response.id); // 1 when searching a specific value

                    // Uncaught TypeError: Cannot call method 'find' of undefined     
                    this.transitionToRoute('article', this.store.find('article', response.id)); 
                    }
                });
            }

        }
    }
});
我被第二个
呼叫卡住了。TransitionRoute
呼叫。它在同一个控制器中。但是,最后一个返回
未捕获类型错误:无法调用未定义的方法“find”

这与getJSON方法有关吗?我尝试在getJSON调用之外调用转换。但这样的承诺就行不通了


有人经历过这种调用吗?

更改
然后
的内部范围,在then外部设置对
的引用,并在then内部使用该引用(如我在下面使用
self
时所做的)


更改
然后
内部的范围,在然后外部设置对
的引用,并在然后内部使用该引用(如我在下面使用
self


非常感谢。当我编辑我的问题以获取更多信息时,您已经键入了答案!然而,我把我的问题称为17点编程停电。我知道这种感觉,它发生在我们所有人身上。谢谢!当我编辑我的问题以获取更多信息时,您已经键入了答案!然而,我把我的问题称为17点编程停电。我知道这种感觉,它发生在我们所有人身上。
App.ApplicationController = Ember.Controller.extend({
    // the initial value of the `search` property
    query: '',

    actions: {
        searchQuery: function () {
            var self = this;
            // the current value of the text field
            var query = this.get('search');

            // numeric search
            if (parseInt(query) > 0) {
                this.transitionToRoute('article', this.store.find('article', query)); // works
            }
            // string search
            else {
                // search database for the search keyword
                jQuery.getJSON("/search/article/" + query + "").then(function(response){
                    if(parseInt(response.id) > 0){
                        console.log(response.id); // 1 when searching a specific value

                    // Uncaught TypeError: Cannot call method 'find' of undefined     
                    self.transitionToRoute('article', self.store.find('article', response.id)); 
                    }
                });
            }

        }
    }
});