本文整理匯總了TypeScript中@proactive/extensions.ObservableArray.push方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ObservableArray.push方法的具體用法?TypeScript ObservableArray.push怎麽用?TypeScript ObservableArray.push使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@proactive/extensions.ObservableArray
的用法示例。
在下文中一共展示了ObservableArray.push方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it("for: bind to an observable array adding/removing", async (t) => {
const template = `<ul><li x-for:value="src" x-text="value"></li></ul>`;
const el = parse(template)[0] as HTMLElement;
const array = new ObservableArray([1, 3, 5]);
t.notThrows(() => ui.domManager.applyDirectives({ src: array }, el));
array.push(7);
t.is(el.children.length, array.getValue().length);
t.deepEqual(toArray(el.children).map((node) => parseInt(node.textContent || "")), array.getValue());
array.pop();
t.is(el.children.length, array.getValue().length);
t.deepEqual(toArray(el.children).map((node) => parseInt(node.textContent || "")), array.getValue());
array.shift();
t.is(el.children.length, array.getValue().length);
t.deepEqual(toArray(el.children).map((node) => parseInt(node.textContent || "")), array.getValue());
array.unshift(9);
t.is(el.children.length, array.getValue().length);
t.deepEqual(toArray(el.children).map((node) => parseInt(node.textContent || "")), array.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");
});