【问题标题】:Render object in form html tag in extjs在 extjs 中以表单 html 标记呈现对象
【发布时间】:2015-06-22 05:00:44
【问题描述】:

我正在使用 extjs 3.4。我有一个表格。在里面我想显示一些ajax内容。但是每当警告该变量时,我都会得到[object object]。我试过stringifyJson.decode 但没有运气。这是我的代码,

var sourcePath = new Ext.data.Store({
                reader: new Ext.data.JsonReader({
                    fields: ['path'],
                    root: 'rows'
                }),
                proxy: new Ext.data.HttpProxy({
                    url: '/plugin/BODImageImport/admin/getsourcepath'
                }),
                autoLoad: true
            });

还有我的表格,

var bodimportForm = new Ext.form.FormPanel({
            html: "<p>Imgae source: <b>"+ sourcePath +"</b> folder in root directory</p>",
            url: '/plugin/BODImageImport/admin/import',

任何帮助或提示都会对我很有帮助。

更新:

我的 Json 是这样的,

{"rows":[{"path":"bodyshop\/tr\/media\/inbox"}]}

我只是想在 html 标记中获取该路径。

更新: 当我使用 console.log() 打印对象时,我得到了下面的东西。但我不知道如何获得我的价值,

【问题讨论】:

    标签: javascript json extjs extjs3


    【解决方案1】:

    这里的sourcePath是一个store实例。

    所以你不能做html:

    图片来源:"+ sourcePath +"

    为了获得商店内的价值,你必须这样做

    //index you are interested
    m = sourcePath.getAt( index ) //this will give the model m
    //m.path to get the path
    

    在你的阅读器中

    reader: new Ext.data.JsonReader({
                        fields: ['path'],
                        root: 'rowsDir'
                    }),
    

    应该是

    reader: new Ext.data.JsonReader({
                        fields: ['path'],
                        root: 'rows'
                    }),
    

    因为你的 json 根是 rows 而不是 rowsDir

    【讨论】:

    • 谢谢西里尔。我尝试了m = sourcePath.getAt( index ); alert(m.path);,但我在控制台中遇到了错误,例如ReferenceError: index is not defined m = sourcePath.getAt( index );
    • 如果您对列表中的第一条记录感兴趣,您需要将索引传递为 0 m = sourcePath.getAt( 0 ) 而不是警报,我建议您执行 console.log(m) 并检查浏览器控制台中的 json。
    • 是的,我试过了,但我得到了TypeError: m is undefined。在控制台日志中,我收到 undefined
    • 你在做console.log(sourcePath.data.items[0].data.path)时得到你的路径
    猜你喜欢
    • 2018-06-13
    • 2013-08-19
    • 2017-04-08
    • 1970-01-01
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多