GVKun编程网logo

javascript – 从json store extjs获取记录(js如何获取json内的数据)

12

对于想了解javascript–从jsonstoreextjs获取记录的读者,本文将提供新的信息,我们将详细介绍js如何获取json内的数据,并且为您提供关于Extjs显示从数据库取出时间转换JSON

对于想了解javascript – 从json store extjs获取记录的读者,本文将提供新的信息,我们将详细介绍js如何获取json内的数据,并且为您提供关于Extjs显示从数据库取出时间转换JSON后的出现问题_javascript技巧、javascript Ext JS 状态默认存储时间_extjs、javascript – ExtJS4 LinkButton组件、javascript – Extjs多重继承?的有价值信息。

本文目录一览:

javascript – 从json store extjs获取记录(js如何获取json内的数据)

javascript – 从json store extjs获取记录(js如何获取json内的数据)

我有一个json存储加载,我需要从中获取一条记录.
我用过:getAt(index),find(),getById(),但没有结果.
这是我的代码:

var appSettingReader = new Ext.data.JsonReader({     
                root: ''results'',
              },[
                {name: ''id'', type: ''int'', mapping: ''id''},
                {name: ''projetId'', type: ''int'', mapping: ''projetId''},
                {name: ''resLevels'', type: ''int'', mapping: ''resLevels''},
                {name: ''maxResToLock'',  type: ''int'', mapping: ''maxResToLock''},
                {name: ''maxTimetoLock'', type: ''int'', mapping: ''maxTimetoLock''},
                {name: ''infosToPrint'', type: ''string'', mapping: ''infosToPrint''}
              ])

var appSettingStore = new Ext.data.Store({
                proxy: new Ext.data.HttpProxy({
                        url: ''inc/getSettings.PHP'',
                        method: ''POST''
                    }),
                baseParams:{task: "app"}, 
                reader : appSettingReader,
                sortInfo:{field: ''id'', direction: "DESC"}
               })

appSettingStore.load(); 

此代码返回undefined:

console.log(appSettingStore.getAt(0));

console.log(appSettingStore.find("id","1")); 

这是从服务器返回的json字符串:

{success:true,"results":[{"id":"1","projetId":"1","resLevels":"1","maxResToLock":"40","maxTimetoLock":"10","infosToPrint":"1_2_3_5","hotlineMail":"admin@app.com"}]}

我也测试了这段代码:

var records = new Array()       
var test = appSettingStore.each(function(rec){
            records.push(rec)
         })
console.log(records)

我得到一个空数组!

PS:这个商店不受任何组件的约束;
我只想读写它.

解决方法:

您需要在商店上放置一个回调,它将在加载后触发.然后,您可以根据需要使用数据.

store.load({
    callback : function(r, options, success) {
        console.log(r.data)
    }
})

总结

以上是小编为你收集整理的javascript – 从json store extjs获取记录全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

原文地址:https://codeday.me/bug/20190726/1545030.html

Extjs显示从数据库取出时间转换JSON后的出现问题_javascript技巧

Extjs显示从数据库取出时间转换JSON后的出现问题_javascript技巧

后台从数据库取出时间,JSON格式化后再传到gridpanel,这时时间变成了:/Date(32331121223)/这样的格式,那么这时需要以下处理才可以正常显示:

复制代码 代码如下:

var record = Ext.data.Record.create([
{ name: ''PublicDate'', mapping: ''PublicDate'', dateFormat: ''Y-m-d'', convert: function (v) {
if (v == null) {
return null;
}
var d = new Date();
var str = v.toString();
var str1 = str.replace("/Date(", "");
var str2 = str1.replace(")/", "");
var dd = parseInt(str2);
d.setTime(dd);
return d;
} }
]);

然后在:
复制代码 代码如下:

var cm = new Ext.grid.ColumnModel([
{ header: ''发布时间'', dataIndex: ''PublicDate'', width: 120, align: ''center'', renderer: Ext.util.Format.dateRenderer(''Y-m-d'') }
]);

这样即可正常显示,如:2012-11-19,

javascript Ext JS 状态默认存储时间_extjs

javascript Ext JS 状态默认存储时间_extjs

复制代码 代码如下:

Ext.state.CookieProvider = function(config){
Ext.state.CookieProvider.superclass.constructor.call(this);
this.path = "/";
this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
this.domain = null;
this.secure = false;
Ext.apply(this, config);
this.state = this.readCookies();
};
Ext.state.CookieProvider = function(config){
Ext.state.CookieProvider.superclass.constructor.call(this);
this.path = "/";
this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
this.domain = null;
this.secure = false;
Ext.apply(this, config);
this.state = this.readCookies();
};

我们可以通过设定expires的值来改变默认的存储时间,比如:
复制代码 代码如下:

this.expires: new Date(new Date().getTime()+(1000*60*60*24*365)), //一年
this.expires: new Date(new Date().getTime()+(1000*60*60*24*365)), //一年

或者我们可以在开始位置的Ext.onReady函数中加上以下的代码
复制代码 代码如下:

Ext.state.Manager.setProvider(
new Ext.state.CookieProvider({
expires: new Date(new Date().getTime()+(1000*60*60*24*365)), //一年
}));

javascript – ExtJS4 LinkButton组件

javascript – ExtJS4 LinkButton组件

我正在尝试在Ext JS 4中创建自己的LinkBut​​ton组件.没什么新鲜的,对吧?

我的代码看起来像这样:

Ext.define(''LinkButton'', {
    extend: ''Ext.Component'',
    xtype: ''linkbutton'',
    autoEl: ''a'',
    renderTpl: ''<a href=\"javascript:;\">{text}</a>'',
    config: {
        text: '''',
        handler: function () { }
    },
    initComponent: function () {
        var me = this;
        me.callParent(arguments);

        this.renderData = {
            text: this.getText()
        };

        var handler = me.getHandler();
        if (handler) {
            me.on(''click'', handler);
        }
    }
});

到现在为止还挺好!我的LinkBut​​ton看起来像一个超链接和我的文本内容.优美.

但是,当我点击它时,我无法让我的组件触发事件!

这个特殊的行me.on(‘click’,handler);不管用!即使我从on更改为addListener它也没有效果.

所以问题是:如何将DOM事件添加到我的组件中?或者,更好的是,如何访问我自己的组件的DOM元素?我无法做到这一点!

谢谢!

解决方法:

这是我的命题,它基于Button组件的源代码:

Ext.define(''LinkButton'', {
    extend: ''Ext.Component'',
    xtype: ''linkbutton'',
    autoEl: ''a'',
    renderTpl: ''<a href=\"javascript:;\" id="{id}-btnEl">{text}</a>'',
    config: {
        text: '''',
        handler: function () { }
    },
    initComponent: function () {
        var me = this;
        me.callParent(arguments);

        this.renderData = {
            text: this.getText()
        };
    },
    onRender: function(ct, position) {
        var me = this, 
            btn;

        me.addChildEls(''btnEl'');

        me.callParent(arguments);

        btn = me.btnEl;

        me.mon(btn, ''click'', me.onClick, me);
    },
    onClick: function(e) {
        var me = this;
        if (me.preventDefault || (me.disabled && me.getHref()) && e) {
            e.preventDefault();
        }
        if (e.button !== 0) {
            return;
        }
        if (!me.disabled) {
            me.fireHandler(e);
        }
    },
    fireHandler: function(e){
        var me = this,
            handler = me.handler;

        me.fireEvent(''click'', me, e);
        if (handler) {
            handler.call(me.scope || me, me, e);
        }
    }
});

工作样本:http://jsfiddle.net/lolo/AEwH4/1/

总结

以上是小编为你收集整理的javascript – ExtJS4 LinkBut​​ton组件全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

原文地址:https://codeday.me/bug/20190902/1790598.html

javascript – Extjs多重继承?

javascript – Extjs多重继承?

我有一个关于ExtJS中的多重继承的问题.虽然我知道我可以简单地复制代码以使其发生,但我想知道是否有任何方法可以更有效地编码它.

我的框架中有一个自定义的GridPanel组件,名为Kore.ux.grid.GridPanel.它扩展了Ext.GridPanel,具有额外的通用功能,并为REST操作提供接口.

不久之后,我的同事想要以同样的方式实现EditorGridPanel,即她希望它可以编辑,同时,能够轻松地执行REST操作.

我的问题是,有什么方法可以扩展Ext.EditorGridPanel来采用自定义的Kore.ux.grid.GridPanel功能吗?

对不起任何语法错误,如果它令人困惑我可以改写它.谢谢!!

编辑

我再次搜索,我发现线程说这是不可能的.如果我有这个问题,我应该遵循更好的编码模式吗?

谢谢!

再次编辑

很抱歉,我找到了适合我的结构..这是我发现对我有用的方法:

var Common = function(){}   //abstract class
Ext.apply(Common.prototype, {

    a : function(){},
    b: function(){}...

});

Ext.ux.somePanelA = Ext.extend ( Ext.Panel, {

    stuff : ............

});

Ext.ux.somePanelB = Ext.extend ( Ext.Panel, {

    diffStuff : ............

});

Ext.applyIf(Ext.ux.somePanelA.prototype, Common.prototype);
Ext.apply(Ext.ux.somePanelB.prototype, Common.prototype);

代码来源:http://www.sencha.com/forum/showthread.php?48000-multiple-inheritance&p=228271&viewfull=1#post228271

如果您认为自己有更好的解决方案,请再次提供有用的建议:)谢谢!

解决方法:

你真正需要研究的是ExtJS插件.

/**
 * Boilerplate code taken from ''ExtJS in Action'' by Jay Garcia
 */
YourNameSpace.RestGridplugin = Ext.extend(Object, {
  constructor : function(config) {
    config = config || {};
    Ext.apply(this.config);
  },

  init : function(parent) { //parent argument here, is whatever you apply your plugin to
    parent.on(''destroy'', this.onDestroy, this);
    Ext.apply(parent, this.parentOverrides);
  },

  onDestroy : function() {
    //here you need to free any resources created by this plugin
  },

  parentOverrides : {
    //here you do your magic (add functionality to GridPanel)
  }

});

Ext.preg(''restgridplugin'',YourNameSpace.RestGridplugin); //register your brand ne plugin

用法

someGrid = {
  xtype: ''grid'',
  columns: ...
  store: ...
  plugins: [
    ''restgridplugin''
  ]
}

someEditorGrid = {
  xtype: ''editorgrid'',
  columns: ...
  store: ...
  plugins: [
    ''restgridplugin''
  ]
}

总结

以上是小编为你收集整理的javascript – Extjs多重继承?全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

原文地址:https://codeday.me/bug/20190521/1149202.html

关于javascript – 从json store extjs获取记录js如何获取json内的数据的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Extjs显示从数据库取出时间转换JSON后的出现问题_javascript技巧、javascript Ext JS 状态默认存储时间_extjs、javascript – ExtJS4 LinkButton组件、javascript – Extjs多重继承?的相关知识,请在本站寻找。

本文标签: