【问题标题】:I am unable to get combo box values我无法获得组合框值
【发布时间】:2015-07-08 12:30:30
【问题描述】:

我有这样的组合框表单

Ext.define('test.view.user.ComboBox', {
extend : 'Ext.form.ComboBox',
alias : 'widget.comboBox',
fieldLabel : 'Employee Id',
hiddenName : 'EmpId',
//url :'test/empIdList',
store : 'EmpIdStore',
valueField : 'value',
displayField : 'text',
triggerAction : 'all',
name:'empId',
editable : false,
allowBlank: false,
//autoSelect:true,
  // forceSelection:true,
listeners : {
    select: function() 
    {
        this.store.load();{
        alert("hello");
        }
    }
}
});

我有这家店

Ext.define('test.store.EmpIdStore', {
extend: 'Ext.data.Store',

itemId:'empIdStore',

reader: new Ext.data.JsonReader({
    data : [['', '']],
fields: ['EmployeeId', 'userId'],
}),
proxy: new Ext.data.HttpProxy({
    type:'ajax',
url: 'test/empIdList'
})
});

点击组合框时我无法获取值。

我在这个应用程序中使用 Hibernate、Spring MVC 和 extjs MVC。在我的 spring 控制器中,我有这样的 empIdList 方法

@RequestMapping(value = "/empIdList", method = { RequestMethod.POST , RequestMethod.GET})
public void empIdList(HttpServletRequest request,HttpServletResponse response) throws Exception {
    System.out.println("Hitting db");
    String userId="";
    String s=userDao.empIdList(userId);
    System.out.println(s);
    PrintWriter out = response.getWriter();
    out.println(s);
}

我在 UserDaoImpl 类中有这样的实现方法

@Override
public String empIdList(String data) 
{
    String id="";
    List<User> lstUsers = new ArrayList<User>();
    lstUsers = hibernateTemplate.loadAll(User.class);
    for (int i = 0; i < lstUsers.size(); i++) {
        id = lstUsers.get(i).getUserId();
        System.out.println(" Employee id "+id);
        User obj=new User();
        obj.setUserId(id);
        Gson gson = new Gson();
        String json = gson.toJson(obj); 
        System.out.println(json);
    }
    return id; 
}

谁能帮我获取组合框的值?

【问题讨论】:

  • 我不明白你的问题。但是在浏览代码时,我注意到商店的 URL 是 test/empIdList,而在您的控制器中它只是/empIdList。你能更详细地解释这个问题吗?我不明白组合框将从哪里加载?
  • 其实我正在做一个应用程序。因为我需要使用组合框从数据库中获取员工 ID 的值
  • 我认为您正在为 json 返回 id。这就是为什么你在 extjs 中没有得到任何值的原因。在您的 empIdList 方法中。这就是问题所在,因为您的 UserDaoImpl 只返回 id 而不是 json。 EXTJS 除了 JSON 之外什么都不会理解。所以它没有显示任何东西。如果您觉得这很有用,我会将其发布为您问题的答案
  • 您是否尝试过弄清楚系统的哪个部分有效,哪个无效?
  • 好。你能发布同样的问题是如何解决的。您可以发布问题的答案

标签: java spring hibernate extjs combobox


【解决方案1】:

通过更改存储中的代理,我得到了结果。这是我的代码

Ext.define('test.store.EmpIdStore', {
extend: 'Ext.data.Store',
alias : 'widget.empIdStore',
autoLoad: false,
fields: ['id', 'userId'],
proxy: {
    type: 'ajax',
    url: 'test/empIdList',
    reader: {
        type: 'json',
        root: 'data'
    }
}
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多