How to use the tns-core-modules/data/observable-array.ObservableArray function in tns-core-modules

To help you get started, we’ve selected a few tns-core-modules examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NativeScript / NativeScript / tests / app / data / observable-array-tests.ts View on Github external
export const test_ObservableArray_sortShouldReturnNewSortedArray = function () {
    // >> observable-array-sort
    const array = new ObservableArray([3, 2, 1]);
    const result = array.sort();
    // << observable-array-sort
    TKUnit.assert(result[0] === 1 && result.length === 3, "ObservableArray sort() should return new sorted array!");
};
github NativeScript / NativeScript / tests / app / data / observable-array-tests.ts View on Github external
export const test_ObservableArray_sliceWithParamsShouldReturnSectionAsNewArray = function () {
    // >> observable-array-slice-args
    const array = new ObservableArray([1, 2, 3, 4, 5]);
    const result = array.slice(2, 4);
    // << observable-array-slice-args
    TKUnit.assert(result[1] === 4 && result.length === 2, "ObservableArray slice() should return section according to specified arguments!");
};
github NativeScript / NativeScript / tests / app / data / observable-array-tests.ts View on Github external
export const test_ObservableArray_indexOfShouldReturnCorrectIndex = function () {
    // >> observable-array-indexof
    const array = new ObservableArray(["one", "two", "three"]);
    const result = array.indexOf("two");
    // << observable-array-indexof
    TKUnit.assert(result === 1, "ObservableArray indexOf() should return correct index!");
};
github NativeScript / NativeScript / tests / app / data / observable-array-tests.ts View on Github external
export const test_ObservableArray_unshiftShouldInsertNewElementsFromTheStartAndRaiseChangeEventWithCorrectArgs = function () {
    let result: ChangedData;

    // >> observable-array-unshift-change
    const array = new ObservableArray([1, 2, 3]);
    array.on(ObservableArray.changeEvent, (args: ChangedData) => {
        //// Argument (args) is ChangedData.
        //// args.eventName is "change".
        //// args.action is "add".
        //// args.index is 0.
        //// args.removed.length is 0.
        //// args.addedCount is equal to the number of inserted items.

        // >> (hide)
        result = args;
        // << (hide)
    });

    array.unshift(4, 5);
    // << observable-array-unshift-change
github NativeScript / NativeScript / tests / app / data / observable-array-tests.ts View on Github external
export const test_ObservableArray_spliceShouldInsertNewItemsInPlaceOfRemovedItemsStartingFromSpecifiedIndex = function () {
    // >> observable-array-splice-args
    const array = new ObservableArray(["one", "two", "three"]);
    const result = array.splice(1, 2, "six", "seven");
    // << observable-array-splice-args
    TKUnit.assert(result.length === 2 && result[0] === "two" && array.length === 3 && array.getItem(2) === "seven",
        "ObservableArray splice() should insert new items in place of removed!");
};
github NativeScript / nativescript-picker / demo / app / examples / value-api / value-api-model.ts View on Github external
private getItems(size: number) {
        let array = new ObservableArray();

        for (let i = 0; i < size; i++) {
            array.push(new DataItem("Item " + i, i, "Description " + i));
        }

        return array;
    }
}
github NativeScript / nativescript-app-templates / packages / template-master-detail-kinvey / app / cars / cars-list-view-model.js View on Github external
.then((cars) => {
                    this.set("cars", new ObservableArray(cars));
                    this.set("isLoading", false);
                })
                .catch(() => {
github NativeScript / nativescript-picker / demo / app / examples / getting-started / getting-started-model.ts View on Github external
private getItems(size: number) {
        let array = new ObservableArray();

        for (let i = 0; i < size; i++) {
            array.push("Item " + i);
        }

        return array;
    }
}
github NativeScript / nativescript-app-templates / packages / template-master-detail-ts / app / cars / cars-list-view-model.ts View on Github external
.subscribe((cars: Array) => {
                    this.cars = new ObservableArray(cars);
                    this.isLoading = false;
                });