空的可观察数组 - knockoutjs

时间:2017-02-15 13:48:25

标签: javascript jquery knockout.js

我有以下代码。但我不确定为什么名称可观察数组是空的。它不会在html上填充任何内容。

    function SolViewModel() {

        names = ko.observableArray([{
            "type": "optiongroup",
            "label": "The Griffins",
            "children": [
                                    { "type": "option", "value": "Peter", "label": "Peter Griffin" },
                                    { "type": "option", "value": "Lois", "label": "Lois Griffin" },
                                    { "type": "option", "value": "Chris", "label": "Chris Griffin" },
                                    { "type": "option", "value": "Meg", "label": "Meg Griffin" },
                                    { "type": "option", "value": "Stewie", "label": "Stewie Griffin" }
            ]
        }
        ]);



        $(function () {
            $('#my-select').searchableOptionList({
                data: function () {
                    var dataInSolFormat = names ; // this is empty
                    return dataInSolFormat;
                }
            });
        });
    }

    ko.applyBindings(new SolViewModel());

1 个答案:

答案 0 :(得分:1)

你需要使用()类似的名字()来访问observable。

相关问题