Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过列表<&燃气轮机;到Javascript并在组合框c中显示#_Javascript_C#_List_Combobox - Fatal编程技术网

如何通过列表<&燃气轮机;到Javascript并在组合框c中显示#

如何通过列表<&燃气轮机;到Javascript并在组合框c中显示#,javascript,c#,list,combobox,Javascript,C#,List,Combobox,我有一个列表,其中存储了从数据库中筛选出的一些记录。 我对Javascript一无所知。有人可以教我如何将列表传递给Javascript并在组合框中显示它吗? P/S:我希望组合框文本字段存储名称(允许用户查看),值字段存储名称ID(对用户隐藏) 我的c#代码如下: public static List<bllControls> getPropertyTypeByPhaseId(int prmPhaseId) { bllControls clsControls = new b

我有一个列表,其中存储了从数据库中筛选出的一些记录。 我对Javascript一无所知。有人可以教我如何将列表传递给Javascript并在组合框中显示它吗? P/S:我希望组合框文本字段存储名称(允许用户查看),值字段存储名称ID(对用户隐藏)

我的c#代码如下:

public static List<bllControls> getPropertyTypeByPhaseId(int prmPhaseId)
{
    bllControls clsControls = new bllControls();
    List<bllControls> lstControls = new List<bllControls>();
    lstControls = clsControls.PropertyTypeSource(prmPhaseId);

    return lstControls;
}
function onSelectedPhase(comboPhase) {
        var phaseId = comboPhase.GetValue();
        PageMethods.getPropertyTypeByPhaseId(phaseId, onSuccess, onFailed);
        function onSuccess(oaCompProj) {
            //here should loop the List and then store in combobox
        }
        function onFailed(oaCompProj) { alert('Failed to get Company and Project info'); }
    }

我的组合框id是ddlProperty。

我刚刚提供了javascript逻辑,以便在组合框中添加元素,如下所示

var cb = document.getElementById("comboBoxId"); // combo box widget
var lstItem = [
    {
        nameId: 1,
        name: "John"
    },
    {
        nameId: 2,
        name: "Doh"
    }
]; 

// Solution 1
for(var i = 0; i < lstItem.length; i++) {
    var item = lstItem[i];
    var elem = document.createElement("option");
    elem.textContent = item.name;
    elem.value = item.nameId;
    cb.appendChild(elem);
}​

// Solution 2  if var lstItem = ['0001@ABC', '0002@DEF'];
for(var i = 0; i < lstItem.length; i++) {
    var item = lstItem[i].split('@');
    var elem = document.createElement("option");
    elem.textContent = item[1]; // for character after '@' e.g. ABC or DEF
    elem.value = item[0]; // for character before '@' e.g. 0001 or 0002
    cb.appendChild(elem);
}​
var cb=document.getElementById(“comboBoxId”);//组合框小部件
变量lstItem=[
{
姓名ID:1,
姓名:“约翰”
},
{
姓名ID:2,
姓名:“Doh”
}
]; 
//解决方案1
对于(变量i=0;i
请在从数据库检索数据后采用此概念。
享受它。

我刚刚提供了javascript逻辑,以便在组合框中添加元素,如下所示

var cb = document.getElementById("comboBoxId"); // combo box widget
var lstItem = [
    {
        nameId: 1,
        name: "John"
    },
    {
        nameId: 2,
        name: "Doh"
    }
]; 

// Solution 1
for(var i = 0; i < lstItem.length; i++) {
    var item = lstItem[i];
    var elem = document.createElement("option");
    elem.textContent = item.name;
    elem.value = item.nameId;
    cb.appendChild(elem);
}​

// Solution 2  if var lstItem = ['0001@ABC', '0002@DEF'];
for(var i = 0; i < lstItem.length; i++) {
    var item = lstItem[i].split('@');
    var elem = document.createElement("option");
    elem.textContent = item[1]; // for character after '@' e.g. ABC or DEF
    elem.value = item[0]; // for character before '@' e.g. 0001 or 0002
    cb.appendChild(elem);
}​
var cb=document.getElementById(“comboBoxId”);//组合框小部件
变量lstItem=[
{
姓名ID:1,
姓名:“约翰”
},
{
姓名ID:2,
姓名:“Doh”
}
]; 
//解决方案1
对于(变量i=0;i
请在从数据库检索数据后采用此概念。
享受吧。

谢谢您的回复。我想再问一个问题:如果我的lstItem以这种格式存储(“0001@ABC)如何使用“@”syombol拆分lstItem并将其存储到组合框中?var a='00001@ABC'; var sptItem=a.split('@');var nameId=sptItem[0];变量名称=sptItem[1]@我刚刚为你们编辑了我的答案。请看解决方案2。非常感谢!谢谢你的帮助!:)@欢迎,你能投票并把我的答案记为最好的吗?谢谢你的回复。我想再问一个问题:如果我的lstItem以这种格式存储(“0001@ABC)如何使用“@”syombol拆分lstItem并将其存储到组合框中?var a='00001@ABC'; var sptItem=a.split('@');var nameId=sptItem[0];变量名称=sptItem[1]@我刚刚为你们编辑了我的答案。请看解决方案2。非常感谢!谢谢你的帮助!:)@欢迎,你能投票并把我的答案记为最好的吗?