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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -