I am attempting to create wizard like view in which each page contains it's own viewmodel
I started out doing something like this to get the templates right:
Everything works fine: http://jsfiddle.net/RyD54/
However, the subsequent pages need to have knowledge of the previous pages viewmodel's data in order to properly display options.
I have tried directly accessing the second viewmodel like this:
Which ends up producing garbage in the drop down lists. http://jsfiddle.net/LvyB3/
I have tried modifying the locales value to be a dependent observable, thinking that accessing the second viewmodel directly changes the scope:
But that produces the same garbage data. http://jsfiddle.net/yarut/
I'm not sure what I am doing wrong to access the uploadedFiles list properly.
Any help would be appreciated.
EDIT
I started out doing something like this to get the templates right:
<
div
id
=
"example"
data-template
=
"template"
data-bind
=
"source: locales"
></
div
>
<
script
id
=
"template"
type
=
"text/x-kendo-template"
>
<
div
>
<
label
data-bind
=
"text: target"
></
label
>
<
select
data-text-field
=
"Filename"
data-value-field
=
"Path"
data-bind
=
"value: Path, source:parent().parent().uploadedFiles"
data-role
=
"dropdownlist"
></
select
>
</
div
>
</
script
>
var
viewModel = kendo.observable({
uploadedFiles : [{Filename:
"..."
, Path:
""
}, {Filename:
"1"
, Path:
""
}, {Filename:
"2"
, Path:
""
}],
locales: [{ target:
'German'
}, { target:
'French'
}, { target:
'Italian'
}, { target:
'Japanese'
}, { target:
'Chinese (Simplified)'
}]
});
kendo.bind($(
"#example"
), viewModel);
However, the subsequent pages need to have knowledge of the previous pages viewmodel's data in order to properly display options.
I have tried directly accessing the second viewmodel like this:
<
div
id
=
"example"
data-template
=
"template"
data-bind
=
"source: locales"
></
div
>
<
script
id
=
"template"
type
=
"text/x-kendo-template"
>
<
div
>
<
label
data-bind
=
"text: value"
></
label
>
<
select
data-text-field
=
"Filename"
data-value-field
=
"Path"
data-bind
=
"value: Path, source:uploadedFiles"
data-role
=
"dropdownlist"
></
select
>
</
div
>
</
script
>
var
viewModel2 = kendo.observable({
selectedLocales: [
'German'
,
'French'
,
'Italian'
,
'Japanese'
,
'Chinese (Simplified)'
]
});
var
viewModel = kendo.observable({
uploadedFiles : [{Filename:
"..."
, Path:
""
}, {Filename:
"1"
, Path:
""
}, {Filename:
"2"
, Path:
""
}],
locales: viewModel2.selectedLocales
});
kendo.bind($(
"#example"
), viewModel);
I have tried modifying the locales value to be a dependent observable, thinking that accessing the second viewmodel directly changes the scope:
var
viewModel2 = kendo.observable({
selectedLocales: [
'German'
,
'French'
,
'Italian'
,
'Japanese'
,
'Chinese (Simplified)'
]
});
var
viewModel = kendo.observable({
uploadedFiles : [{Filename:
"..."
, Path:
""
}, {Filename:
"1"
, Path:
""
}, {Filename:
"2"
, Path:
""
}],
locales:
function
() {
return
viewModel2.get(
"selectedLocales"
);
}
});
kendo.bind($(
"#example"
), viewModel);
I'm not sure what I am doing wrong to access the uploadedFiles list properly.
Any help would be appreciated.
EDIT
The issue has become a bit more complicated: In production the list of source languages is going to be coming from a multi-select in the other viewmodel. My idea is to create a calculated field that builds a observableobject that contains the selectedLanguages, an instance of the uploadedFiles array and a selectedFile variable to hold the selection:
aspx:
<
div
id
=
"example2"
>
<
h5
>Target</
h5
>
<
select
multiple
=
"multiple"
data-value-field
=
"id"
data-text-field
=
"name"
data-bind
=
"source: availableLocales, value: selectedLocales"
></
select
>
</
div
>
<
div
id
=
"example"
>
<
div
data-template
=
"template"
data-bind
=
"source: locales"
></
div
>
</
div
>
<
script
id
=
"template"
type
=
"text/x-kendo-template"
>
<
div
>
<
label
data-bind
=
"text: target"
></
label
>
<
select
data-text-field
=
"Filename"
data-value-field
=
"Path"
data-bind
=
"value: selectedFile, source:files"
data-role
=
"dropdownlist"
></
select
>
</
div
>
</
script
>
javascript:
var
viewModel2 = kendo.observable({
selectedLocales: [],
availableLocales: [{id:1, name:
'German'
}, {id:2, name:
'French'
}, {id:3, name:
'Italian'
}, {id:4, name:
'Japanese'
}, {id:5, name:
'Chinese (Simplified)'
}]
});
var
viewModel = kendo.observable({
uploadedFiles : [{Filename:
"..."
, Path:
""
}, {Filename:
"1"
, Path:
""
}, {Filename:
"2"
, Path:
""
}],
locales:
function
() {
var
selected = viewModel2.get(
"selectedLocales"
);
var
availableFiles =
this
.get(
"uploadedFiles"
);
var
processedLocales = [];
for
(
var
i = 0; i < selected.length ; i++) {
processedLocales.push({ target: selected[i].get(
"name"
), files: availableFiles, selectedFile:
null
});
}
return
processedLocales;
}
});
kendo.bind($(
"#example2"
), viewModel2);
kendo.bind($(
"#example"
), viewModel);
fiddle: http://jsfiddle.net/fHrVK/
Of course this doesn't work either...