I am using a view to load a project list after a success login. When a user land to the page after success login i am getting data from api inside a kendo datasource logic. When i see the console my api url call twice. I dont understand why its calling twice.
My index.html
My home-view.js
The above api is fetching the result and show correct, the only thing is it is called twice whenever i load this home-view. I have verified in the console firefox browser. Kindly help this what is the issue with run twice.
My index.html
<!DOCTYPE HTML>
<
html
>
<
head
>
<
link
href
=
"kendo/styles/kendo.mobile.all.min.css"
rel
=
"stylesheet"
/>
<
link
href
=
"css/main.css"
rel
=
"stylesheet"
/>
</
head
>
<
body
>
<
div
data-role
=
"layout"
data-id
=
"home-layout"
>
<
header
data-role
=
"header"
>
<
div
data-role
=
"navbar"
>
<
span
data-role
=
"view-title"
></
span
>
</
div
>
</
header
>
<
div
data-role
=
"footer"
>
<
div
data-role
=
"tabstrip"
>
<
a
href
=
"#home-view"
target
=
"_blank"
data-icon
=
"home"
>Home</
a
>
<
a
href
=
"#login-view"
data-icon
=
"contacts"
>login</
a
>
<
a
href
=
"#about-us"
data-icon
=
"about"
>About</
a
>
</
div
>
</
div
>
</
div
>
<
div
data-role
=
"layout"
data-id
=
"account-layout"
>
<
header
data-role
=
"header"
>
<
div
data-role
=
"navbar"
>
<
span
data-role
=
"view-title"
></
span
>
<
span
data-role
=
"button"
data-bind
=
"click: logout"
data-align
=
"right"
>Log Off</
span
>
</
div
>
</
header
>
<
div
data-role
=
"footer"
>
<
div
data-role
=
"tabstrip"
>
<!-- <a href="#home-view" data-icon="home">Home</a> -->
<
a
href
=
"#login-view"
data-icon
=
"contacts"
>login</
a
>
<!-- <a href="#about-us" data-icon="about">About</a> -->
</
div
>
</
div
>
</
div
>
<
div
data-role
=
"view"
id
=
"login-view"
data-layout
=
"account-layout"
data-model
=
"app.accountView.viewModel"
data-init
=
"app.accountView.navigate"
data-before-show
=
"app.accountView.navigate"
data-title
=
"Log In"
style
=
"display: none;"
>
<
p
>
For demonstration purposes Login example
</
p
>
<
ul
>
<
li
>
<
strong
>Username:</
strong
> owner
</
li
>
<
li
>
<
strong
>Password:</
strong
> p@ssword123
</
li
>
</
ul
>
<
input
type
=
"text"
placeholder
=
"Username"
data-bind
=
"value: loginUsername"
required
data-required-msg
=
"Enter a valid usernmae"
/>
<
input
type
=
"password"
placeholder
=
"Password"
data-bind
=
"value: loginPassword"
required
data-required-msg
=
"Enter a valid password"
/>
<
input
type
=
"url"
data-bind
=
"value: serverURL"
required
data-url-msg
=
"Enter a valid url for server"
/>
<
div
type
=
"button"
data-role
=
"button"
data-bind
=
"click: login"
>
Log In
</
div
>
</
div
>
<
div
data-role
=
"view"
id
=
"home-view"
data-layout
=
"home-layout"
data-title
=
"Home"
data-show
=
"app.homeView.initializeHome"
>
<
ul
id
=
"myProjectCustomListView"
></
ul
>
</
div
>
<
script
id
=
"myProjectCustomListViewTemplate"
type
=
"text/x-kendo-template"
>
<
a
href
=
"projectDetail.html"
id
=
"${ProjectId}"
>
<
h3
class
=
"item-title"
>${ProjectName}</
h3
>
<
p
class
=
"item-info"
>Created Date: ${CreateDate}</
p
>
</
a
>
</
script
>
<!-- <script src="cordova.js"></script> -->
<!-- RequireJS is a JavaScript file and module loader(Below main.js file is set to load) -->
<
script
data-main
=
"scripts/main.js"
src
=
"scripts/require.js"
></
script
>
</
body
>
</
html
>
My home-view.js
define(["jQuery", "kendo", "utils", "common"], function($, kendo, utils, common) {
return {
initializeHome :function() {
console.log("home view initialized")
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "http://127.0.0.1/api/getprojects",
dataType: "json",
cache: false
}
},
});
dataSource.fetch(function() {/** To check how many data are fetched like a total count for reference */
console.log(dataSource.view().length); // displays "77"
});
$("#myProjectCustomListView").kendoMobileListView({
dataSource: dataSource,
template: $("#myProjectCustomListViewTemplate").html(),
});
},
};
});
The above api is fetching the result and show correct, the only thing is it is called twice whenever i load this home-view. I have verified in the console firefox browser. Kindly help this what is the issue with run twice.