jQuery combine data source urls on alpaca library

256 Views Asked by At

in this below code i have to use unique urls to get necessary data form server to use alpaca library , how can i combine this urls to get data from server with one url for example:

http://127.0.0.1:8000/content_categories

my alpaca library implementation is:

$("#content_categories").alpaca({
    "data": [],
    "schema": "http://127.0.0.1:8000/schema",
    "options": "http://127.0.0.1:8000/options",
    "postRender": function (control) {
        $("#multiselect").parent().find("input[type=checkbox]").uniform();
    }
});

and server implementation to send result:

Route::get('/schema', function () {
    echo json_encode(
        ["type" => 'array', 
            "items" => 
                ["type" => "string", 
                    "enum" => ["salam", "ma"], 
                    "minItems" => 1, 
                    "maxItems" => 20
                ]
        ]);

});

Route::get('/options', function () {
    echo json_encode(
        ["helper" => "یک یا چند مورد انتخاب کنید", 
            "type" => "select", 
            "id" => "multiselect", 
            "focus" => false, 
            "size" => 1]
    );
});

for example:

Route::get('/content_categories', function () {
    echo json_encode([
            "schema" => ["type" => 'array',
                "items" =>
                    ["type" => "string",
                        "enum" => ["salam", "ma"],
                        "minItems" => 1,
                        "maxItems" => 20
                    ]
            ],
            "options" => ["helper" => "یک یا چند مورد انتخاب کنید",
                "type" => "select",
                "id" => "multiselect",
                "focus" => false,
                "size" => 1
            ]
        ]
    );
});
1

There are 1 best solutions below

1
On

Yes you can do that with only one webservice which you should call it before alpaca initialization using ajax for example...and you should also devide the response to schema and options objects like this :

"schema": response.schema,
"options": response.options

here's a fiddle for this.