将extjs作为变量传递时,extjs存储代理api引发错误,无法识别url [英] extjs store proxy api throws error does not recognize url when passing it as a variable

查看:153
本文介绍了将extjs作为变量传递时,extjs存储代理api引发错误,无法识别url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一家商店,可从rest api提取数据.事实证明,如果我尝试将url作为变量传递,则会引发以下错误:

I have a store which fetches data from rest api. Turns up that if I try to pass the url as a variable it throws me the following error:

[E] Ext.data.proxy.Server.buildUrl():您正在使用ServerProxy,但未向其提供网址.

[E] Ext.data.proxy.Server.buildUrl(): You are using a ServerProxy but have not supplied it with a url.

这是代码:

Ext.define('mystore', {
    extend: 'Ext.data.Store',
    alias: 'store.mystore',
    model: 'mymodel',
    restful: true,
    autoLoad: true,
    proxy: {
        type: 'ajax',
        headers: {
           'Accept': '*/*',
           'Cache-Control': 'no-cache',
           'Content-Type': 'application/json',
           'Authorization': localStorage.token
        },
        extraParams: {
           sort: 'clave',
           'filter[active]': true
        },

        reader: {
            type: 'json',
            rootProperty: 'data',
            successProperty: 'success'
        },

        writer: {
            type: 'json',
            writeAllFields: true,
            encode: true,
            rootProperty: 'data'
        },

        actionMethods: {
           read: 'GET'
        },

        api: {
           read: this.url,
           create: this.url,
           update: this.url,
           destroy: this.url
        },

        autoSave: true
    },
    constructor: function (config) {
        this.url = 'http://myurl...';
        console.log('>>>>>>>>>>>>>>>>>>>>>>>>',this.url);
        this.callParent(arguments);
        this.initConfig(config);
        return this;
    }
});

到目前为止,我已经阅读了构造函数应该首先部署,然后再部署组件.问题是我对如何解决这个问题一无所知,那么我如何才能使它正常工作呢?我做错了什么方式?

So far I've read the constructor should be deployed in the very first place, and then the component. The thing is I have no idea on how to solve this, so how can I get this working? What am I doing the wrong way?

推荐答案

在网上阅读了大量文章并进行了测试之后,我自己找到了解决方案:( 要做的是构造存储,然后从调用视图的控制器传递url属性,即:

I've found a solution myself, after a lot of reading in web foros and testing :( The thing is to construct the store and then pass url attrib from the controller which calls the view, that is to say:

component.store = Ext.create('mystore', {
            url: 'part of the url'
        });

这样,在加载组件时,它已经知道url的值.希望这会有所帮助.

like this, when the component loads it knows already the value of url. Hope this might help.

这篇关于将extjs作为变量传递时,extjs存储代理api引发错误,无法识别url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆