【问题标题】:How to acces Object property如何访问对象属性
【发布时间】:2019-07-18 21:50:54
【问题描述】:

我有外部 API, 代理是休息, 读者定义, 类型:'json', rootProperty: '数据;

如何获取属性“FullName” 我已尝试使用 record.get('FullName')。

创建的名为 getDetails 的函数,作为参数字符串传递,返回 返回 record.get('FullName),始终未定义。

 Details: function(v, record) {

       return record.get('FullName') 
    }

这里是 onDelete 函数:

OnDelete: function (record,data) {
     Ext.Msg.confirm('Delete Changes', 'Do you want to delete' + " " + record.Details, function (choice) {

            if (choice === 'yes') {
                var store = Ext.getStore('store.Personnel');
                store.remove(record);
                store.sync();

            }
        })
    },

this is how console log on record look like. I have 3 constructors with Id's then data, and then obj properties)

【问题讨论】:

    标签: extjs


    【解决方案1】:

    您应该像这样使用 record.get('FullName'):

    OnDelete: function (grid, rowId) {
        var record = grid.getStore().getAt(rowId);
            Ext.Msg.confirm('Delete Changes', 'Do you want to delete' + " " + record.get('FullName'), function (choice) {
                if (choice === 'yes') {
                    var store = grid.getStore();
                    console.log(store)
                    store.remove(record);
    
                }
            })
        }
    

    你在小提琴上的例子:https://fiddle.sencha.com/#view/editor&fiddle/2ttb

    【讨论】:

    • Ext.define('MyApp.store.Personnel', { extend: 'Ext.data.Store', 别名: 'store.personnel', autoLoad: true, pageSize: null, model: '人员',代理:{类型:'rest',url:'reqres.in/api/users',方法:{读取:'GET',},阅读器:{类型:'json',rootProperty:'data',}},侦听器: { load: function(store, records,) { console.log(records); } } });
    • 在模型中,我有字段“FullName”。我正在使用转换函数来获取全名。由于我也有名字和姓氏字段,并且我想显示全名,我不得不使用转换功能。它从阅读器读取数据并将该字符串转换为对象。
    • 您能否将提供的参数附加到OnDelete 方法:记录和数据?
    • 这里是商店和整个项目的链接。 github.com/MrNoOne007/EXT-JS---App/blob/master/app/store/…
    • 最好将 fiddle 上的示例附加到轻松重新创建,在引用的 github 项目中,我看不到使用 OnDelete 方法的视图。
    猜你喜欢
    • 2019-06-02
    • 2021-03-05
    • 2020-02-11
    • 2019-09-25
    • 2011-06-15
    • 2016-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多