在html下拉框中显示observableArray内容

时间:2014-08-19 10:02:13

标签: javascript knockout.js

任何人都可以帮忙...我想在我的html页面上填充我的下拉框中的数据来自数据库,但我一直收到这个错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

但是当我用chrome检查元素时,数组中充满了数据但是我的下拉框没有填充.....这是我的脚本:

$(document).ready(function() {

    function supplier(data) {
        var self = this;

        self.id = ko.observable(data.supplierNo);
        self.name = ko.observable(data.name);

    }

    function supplierViewModel() {

        var self = this;

        self.suppliers = ko.observableArray([]);        

        $.ajax({
            type: "GET",
            url: "http://localhost:8080/SupplyChainMan/rest/Suppliers/getSuppliers",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(data) {

                var mappedData= $.map(allData, function(data) { return new supplier(data) });

                self.suppliers(mappedData);
                console.log(self.suppliers());

            },
            error: function() {
                alert("Failed to load Supplier");
            }
        });     
    }
        ko.applyBindings(new supplierViewModel());

    });

......我的html很简单:

 <table>
    <tr>
        <th>
            Supplier Name
        </th>
        <td>
            <select data-bind='options: suppliers, optionsText: "name"'></select>
        </td>
    </tr>

</table>

0 个答案:

没有答案