本文整理汇总了TypeScript中@proactive/extensions.ObservableArray类的典型用法代码示例。如果您正苦于以下问题:TypeScript ObservableArray类的具体用法?TypeScript ObservableArray怎么用?TypeScript ObservableArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObservableArray类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("for: bind to an observable array of observables", async (t) => {
const template = `<ul><li x-for:item="src">
<span class="part1" x-text="item.foo"></span>
</li></ul>`;
const el = parse(template)[0] as HTMLElement;
const array = new ObservableArray([ { foo: new BehaviorSubject(1) }, { foo: new BehaviorSubject(5) }, { foo: new BehaviorSubject(7) } ]);
t.notThrows(() => ui.domManager.applyDirectives({ src: array }, el));
array.getValue().forEach((x) => x.foo.next(33));
t.deepEqual(toArray(el.querySelectorAll(".part1"))
.map((node) => parseInt(node.textContent || "")), array.getValue().map((x) => x.foo.getValue()));
});
示例2: it
it("value: select multiple can be bound to an array", async (t) => {
const template = `<select multiple x-value="selected">
<option value="A">A</option>
<option value="B">B</option>
</select>`;
const selected = new ObservableArray<string>([]);
const el = parse(template)[0] as HTMLSelectElement;
const viewmodel = { selected };
ui.domManager.applyDirectives(viewmodel, el);
selected.push("A");
t.is(el.options[0].selected, true, "Dataflow.Out");
el.options[1].selected = true;
triggerEvent(el, "change");
t.is(selected.getValue().length, 2, "Dataflow.In");
});