本文整理匯總了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");
});