NativeScript camera and saving various pictures -
i trying take various photos , take them want them appear in view. idea add photo objects model observable , repeater in view have them displayed.
note instead of image object adding simple strings noteimages debug it.
what have is:
the view model:
function noteviewmodel(info) { info = info || {}; var viewmodel = new observable({ id: info.id || null, title: info.title || "title default", description: info.description || "description default" noteimages: [{src: "xxxx"}, {src: "yyyyyy"}] }); return viewmodel; }
the "controller":
... var noteviewmodel = new noteviewmodel(); exports.loaded = function(args) { console.log("loading note view...") page = args.object; page.bindingcontext = noteviewmodel; }; ... exports.takephoto = function(){ cameramodule.takepicture({width: 300, height: 300, keepaspectratio: true}).then(function(imagesource) { var image = new imagemodule.image(); image.imagesource = imagesource; noteviewmodel.mainimage = imagesource; // noteviewmodel.noteimages.push( {"src": "test"} ); noteviewmodel.noteimages.set([{src: "test"}]); }
and view:
<page loaded="loaded"> <page.actionbar> <actionbar title="new note"></actionbar> </page.actionbar> <stacklayout> <repeater items="{{ noteimages }}"> <repeater.itemtemplate> <label text="{{ src }}" /> <!-- <image src="{{ src }}" /> --> </repeater.itemtemplate> </repeater> </stacklayout> </page>
note: know should adding imagesource array of images, testing purposes want see item added noteimages , shown repeater...
initial noteimages displayed repeater guess bindingcontext working expected. problem when camera returns imagesource , noteviewmodel.noteimages.set([{src: "test"}]); view empty. repeater failing pick new array...
should observable propagate changes on property noteimages ui automatically or noteimages should observablearray itself?
what missing here? :) thanks
edit: making progress...
it seems if observable contains properties arrays these properties must of type observablearray so, model now:
noteimages: new observablearray({src: "image1"}, {src: "image2"})
insead of
noteimages: [{src: "image1"}, {src: "image2"}]
after taking picture do:
noteviewmodel.noteimages.push( {"src":"aaaaaa"} )
and view shows "aaaa"
Comments
Post a Comment