0

我正在尝试在这里使用演示:

http://knockoutjs.com/examples/cartEditor.html

但是,在使用的数据集中,即:sampleProductCategories - 在示例中它是静态的。

我想在通过 jQuery getJson 调用 API 后填充该数据集。

所以标记将存在于页面上 - 但是它还没有数据来填充视图。

当 sampleProductCategories 列表更改时,如何重新触发标记以重绘自身?

例如 - 这部分可以重绘/反弹到数据吗?

 <tbody data-bind='foreach: lines'>
    <tr>
        <td>
            <select data-bind='options: sampleProductCategories, optionsText: "TypeName", optionsCaption: "Select...", value: TypeID'></select>
        </td>
        <td data-bind="with: category">
            <select data-bind='options: products, optionsText: "name", optionsCaption: "Select...", value: $parent.product'></select>
        </td>

谢谢,

标记

4

1 回答 1

1

您可以将 anobservableArray用于您的选项,然后通过 AJAX 请求填充它们。UI 将相应更新。

这是购物车编辑器的更新示例,它使用一个空observableArray并在 1 秒后使用静态数据在 setTimeout 中更新它(就像使用 AJAX 调用一样)。 http://jsfiddle.net/rniemeyer/TmUDc/

于 2012-08-21T13:29:50.353 回答