我正在尝试dijit.form.FilteringSelect,具体取决于响应中定义的类型。在从响应中动态设置存储时,我收到错误:
SCRIPT5007:'中的操作数无效:预期的对象
以下是代码:
var store=this.response.items[i].Name;
var myTextBox = new dijit.form.FilteringSelect({
title:this.response.items[i].DisplayName,
name:this.response.items[i].Name,
type:"picklist",
value: "CA",
store: this.response.items[i].Name,
searchAttr: "name"
});
debugger;
dijit.byId("test").domNode.appendChild(myTextBox.domNode);
var Subsidiary = new dojo.store.Memory({
data: [
{name:"Alabama", id:"AL"},
{name:"Alaska", id:"AK"},
{name:"American Samoa", id:"AS"},
{name:"Arizona", id:"AZ"},
{name:"Arkansas", id:"AR"},
{name:"Armed Forces Europe", id:"AE"},
{name:"Armed Forces Pacific", id:"AP"},
{name:"Armed Forces the Americas", id:"AA"},
{name:"California", id:"CA"},
{name:"Colorado", id:"CO"},
{name:"Connecticut", id:"CT"},
{name:"Delaware", id:"DE"}
]
});
var MainClaimNumber = new dojo.store.Memory({
data: [
{name:"Alabama", id:"AL"},
{name:"Alaska", id:"AK"},
{name:"American Samoa", id:"AS"},
{name:"Arizona", id:"AZ"},
{name:"Arkansas", id:"AR"},
{name:"Armed Forces Europe", id:"AE"},
{name:"Armed Forces Pacific", id:"AP"},
{name:"Armed Forces the Americas", id:"AA"},
{name:"California", id:"CA"},
{name:"Colorado", id:"CO"},
{name:"Connecticut", id:"CT"},
{name:"Delaware", id:"DE"}
]
});
截至目前,我知道有2个FiltetringSelect类型的值,所以我正在硬编码商店的名称。
请指导如何实现这一目标。
答案 0 :(得分:0)
您似乎期待一个字符串可以神奇地插入变量。这不是JavaScript的工作原理。您正在函数范围内定义变量,并有效地设置store: <some string>
并期望<some string>
查找同名变量......但它只是一个字符串。此外,在您尝试分配商店之前,您似乎并未真正定义相关变量。
但是,考虑到你想要做什么,你应该能够通过在对象哈希中创建商店来进行一些小的调整以使其工作,然后使用字符串值来动态查找其中一个键:
var stores = {
Subsidiary: new dojo.store.Memory(...),
MainClaimNumber: new dojo.store.Memory(...)
};
var myTextBox = new dijit.form.FilteringSelect({
// ...
store: stores[this.response.items[i].Name]
});