动态传递参数 [英] Pass parameters dynamically

查看:98
本文介绍了动态传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ExtJS 4从数据库检索图像到数据视图。现在我需要动态地传递参数。大部分在这里..........

  Ext.define('$ {pkgName} .v02x003001.SV02X00300102' ,{
extends:'Ext.view.View',
alias:'widget.sv02x00300102',
id:'images-view',
autoScroll:true,
trackOver:true,
multiSelect:true,
height:310,
overItemCls:'x-item-over',
itemSelector:'div.thumb-wrap'
emptyText:'无图像显示',
prepareData:function(data){
Ext.apply(data,{
shortName:Ext.util.Format.ellipsis .name,15),
sizeString:Ext.util.Format.fileSize(data.size),
dateString:Ext.util.Format.date(data.lastmod,m / d / Y g :
$ b});
返回数据;
},
initComponent:function(){
var me = this;
var value = Ext.getCmp('member-sv02x00300104')。getValue();
me.store ='S02X003001',
me.tpl = [
< tpl for =。>',
'< div class =thumb-wrapid ={name}>',
'< div class = >< img src =$ {createLink(mapping:'img',params:[member:** value **,width:100,height:100])}title ={name}> < / div>',
'< span class =x-editable> {shortName}< / span>< / div>',
'< / tpl& ,
'< div class =x-clear>< / div>'
];

me.callParent(arguments);
}

});



所以我的问题是如何将设置为参数(对于成员字段)

解决方案

在运行JS代码之前,createLink是进程服务器端的grails组件。
您不能将JS变量传递给Java组件,因为Java将始终首先在服务器上进行处理,然后生成的HTML和JS将被发送到客户端进行处理。客户端对于您的服务器端代码块一无所知。



我建议您用HTML重写createLink片段,并用JS变量替换,就像使用名称和短名称一样。 p>

I'm trying to retrieve images from database to data view using ExtJS 4. Now I need to pass parameters dynamically. Mostly here..........

Ext.define('${pkgName}.v02x003001.SV02X00300102' , {
extend       : 'Ext.view.View',
alias        : 'widget.sv02x00300102',        
id           : 'images-view',
autoScroll   : true,
trackOver    : true,
multiSelect  : true,
height       : 310,
overItemCls  : 'x-item-over',
itemSelector : 'div.thumb-wrap',
emptyText    : 'No images to display',
prepareData  : function(data) {
    Ext.apply(data, {
        shortName : Ext.util.Format.ellipsis(data.name, 15),
        sizeString: Ext.util.Format.fileSize(data.size),
        dateString: Ext.util.Format.date(data.lastmod, "m/d/Y g:i a")
    });
    return data;
},    
initComponent: function() {
    var me   = this;
    var value= Ext.getCmp('member-sv02x00300104').getValue();
    me.store = 'S02X003001',
    me.tpl   = [
                '<tpl for=".">',
                '<div class="thumb-wrap" id="{name}">',
                '<div class="thumb"><img src="${createLink(mapping:'img', params:[member: **value** , width:100, height:100])}" title="{name}"></div>',
                '<span class="x-editable">{shortName}</span></div>',
                '</tpl>',
                '<div class="x-clear"></div>'
               ];

    me.callParent(arguments);
}

});

So my question is how do I set value into params ( for member field )

解决方案

createLink is a grails component that is processes server side, before your JS code is run. You can't pass JS variables to a Java component because Java will always be processed first on the server and then the resulting HTML and JS will be sent to the client for processing. Client will know nothing about your server side code blocks.

I suggest you rewrite createLink piece in HTML and substitute in JS variables like you do with name and short name.

这篇关于动态传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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