0

我遇到了有线问题,在应用自定义绑定之前和之后,Array 的记录数为 8,但是在调试绑定时,它们的 Array 为空。由于数组为空,因此 Grid 不显示任何内容。我究竟做错了什么?

var vM = {
            recordsCount: ko.observable(),
            countries: ko.observableArray()
        };
        $(function () {

        getAllCountries();

        // Handler for .ready() called.
        //alert(myns.JavaScript1);
        //alert(myns.JavaScript1);
        //alert(myns.JavaScript2);

    });


    var serviceName = "/breeze/CountriesBreeze/";
    var manager = new breeze.EntityManager(serviceName);

    /***  supporting functions ***/
    function getAllCountries() {
        var query = breeze.EntityQuery.from("GetCountries");
        console.log("Getting Countries");
        return manager.executeQuery(query)
            .then(function(data) {
                vM.countries(data.results);
                alert(vM.countries().length);
                ko.applyBindings(vM);
                alert(vM.countries().length);
            }).fail(
                alert( "Error getting Data")
            )
    }


</script>
<div id="log"></div>

]

                   }">
      </table>
4

1 回答 1

0

将您的ko.applyBindings()声明移至此处:

var vM = {
            recordsCount: ko.observable(),
            countries: ko.observableArray()
        };
        $(function () {

        getAllCountries();

        // Handler for .ready() called.
        //alert(myns.JavaScript1);
        //alert(myns.JavaScript1);
        //alert(myns.JavaScript2);

    });

ko.applyBindings(vM);

然后我不确定这样做vM.countries(data.results)是否有效,您可能需要迭代并推送每个值或执行以下操作:

vM.countries(data.results)
vM.countries.valueHasMutated()
于 2013-07-11T00:13:41.100 回答