Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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
数据绑定jquery mobile multiple select with knockout_Jquery_Dynamic_Mobile_Loading - Fatal编程技术网

数据绑定jquery mobile multiple select with knockout

数据绑定jquery mobile multiple select with knockout,jquery,dynamic,mobile,loading,Jquery,Dynamic,Mobile,Loading,更新 我明白了为什么它不会将数据加载到select…my function company(name, value) { this.name = ko.observable(name); this.value = ko.observable(value); } 应该是 function company(name, value) { this.comapnyName = name; this.companyValue = value; }

更新 我明白了为什么它不会将数据加载到select…my

 function company(name, value) {
        this.name = ko.observable(name);
        this.value = ko.observable(value);
    }
应该是

function company(name, value) {
   this.comapnyName = name;
   this.companyValue = value;
}
因此,它将匹配数据绑定中的预期结构…但是它在开始时仍然没有加载,但只有在我选择某个内容后,它才会从前三个更改为JSON调用加载的那三个…刷新没有触发的原因是什么

更新

我试图将一些项目动态加载到一个多选jquery mobile样式的select中,但使用knockout.js作为后端…这是我的代码…当我在显示test、test1、test2项目的代码中加载viewModel时,它会起作用,但我不想在服务器端加载项目,而是在客户端加载项目,使用$.getJSON调用如下:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
<script type="text/javascript" src="js/knockout-2.0.0.debug.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta charset="utf-8" http-equiv="X-UA-Compatible" content="IE=9" />
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
</head>
<body>
Choose a company: <select id="companies" data-role="select" data-bind="options: companies,
    optionsCaption: 'Choose...',
    optionsText: 'companyName',
    optionsValue: 'companyValue',
    selectedOptions: chosencompanies" data-native-menu="false" multiple></select> 
<input data-bind="value: chosencompanies"></input>    
<script type="text/javascript">
$(document).ready(function () {
    function company(name, value) {
        this.name = ko.observable(name);
        this.value = ko.observable(value);
    }
    var viewModel = {
        companies: ko.observableArray([
                { companyName: "test", companyValue: 0 },
                { companyName: "test1", companyValue: 1 },
                { companyName: "test2", companyValue: 2 }
            ]),
        chosencompanies: ko.observableArray(["0", "1", "2"]),
        resetcompanies: function () { this.chosencompanies(null) }
    };
    $.getJSON("http://localhost/service.svc/json/gc", function (json) {
        //var dataFromServer = ko.utils.parseJson(json);
        var mappedData = ko.utils.arrayMap(json.GetCompaniesRESTResult, function (item){
            return new company(item.LongName, item.ID);
        });
        viewModel.companies(mappedData);
    });
    ko.applyBindings(viewModel);
    $("#companies").selectmenu('refresh', 'true');
});
</script>
</body>
</html>
它没有显示在加载的页面上。当我单击选择按钮并尝试选择某个内容时,我将看到ChosenCompanys输入将保留3个逗号字符,但中间没有任何字符,正如它以前保留的[0,1,2],这是我试图预选select中加载的所有项目的尝试-我还没有做到-因此,如果有人知道,请在此处或上方回答

我给公司分配的价值是错误的吗?或者,指定的值的格式是否有误,即使它传递了一个数组,并在developer safari工具中显示为数组[3]。或者也许那个刷新电话不太好

请帮忙,任何帮助都将不胜感激,我现在主要是开始淘汰赛和jqm

{"GetCompaniesRESTResult":
[{"ID":1,"IsOnline":false,"LongName":"test1","ShortName":"t1"},
{"ID":2,"IsOnline":false,"LongName":"test2","ShortName":"t2"},
{"ID":3,"IsOnline":false,"LongName":"test3","ShortName":"t3"}]}