Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MVC, WebAPI Controllers and LocalStorage
Message
De
04/07/2014 09:58:50
 
 
À
04/07/2014 03:24:53
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 4.0
OS:
Windows 8
Network:
Novell 6.x
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01603183
Message ID:
01603234
Vues:
37
>>Thanks Viv.
>>
>>I have my data stored in local storage and now I want to display it. I've been using knockout like this:
>>
>>
this.runSheetDetails = ko.observableArray(@Html.Raw(Model.RunSheetDetailsJSON));
>>
>>So I've tried changing that like this:
>>
>>
this.runSheetDetails = ko.observableArray(JSON.parse(localStorage[this.localKey]));
>>
>>but then I get binding errors:
>>
>>Uncaught ReferenceError: Unable to process binding "template: function (){return { name:'list-template',foreach:runSheetDetails} }"
>>
>>Do you have an example of reading a list of data from localstorage and displaying it?
>>
>>This is an example of what the json looks like when it comes out of local storage:
>>
>>[[{"airWayBill":{"customer":{"cus_PK":"5df642b5-7889-419b-8a16-a63196f79571","cus_lastname":"Bachan","cus_firstname":"Kathy-Ann","cus_company":"Kath-Ann Bachan","cus_addr1":"23 Alexandra Street","cus_addr2":"C/O British Academy","cus_number":"6695 "},"awb_pk":"b9311877-eaf1-49b3-bfaf-2e8afedce389","awb_pieces":1,"awb_cusfk":"5df642b5-7889-419b-8a16-a63196f79571","awb_number":"99800640310"},"deliveryHistories":[],"runSheetHeader":null,"rnd_pk":"7c8d9f45-813b-4120-945d-91e4cfbaedba","rnd_rnhfk":"548a5288-c65d-43ac-be7c-fec662fc154a","rnd_awbfk":"b9311877-eaf1-49b3-bfaf-2e8afedce389"},{"airWayBill":{"customer":{"cus_PK":"4b0a83af-ef75-4567-b564-d4288ed193a0","cus_lastname":"Ambrose","cus_firstname":"Leonardo","cus_company":"Leonardo Ambrose","cus_addr1":"11 Braemar Rd,","cus_addr2":null,"cus_number":"1463 "},"awb_pk":"bea8497f-b956-4a4a-9702-c5eddcf014c7","awb_pieces":1,"awb_cusfk":"4b0a83af-ef75-4567-b564-d4288ed193a0","awb_number":"99802580636"},"deliveryHistories":[],"runSheetHeader":null,"rnd_pk":"39d225f2-b064-45fa-8034-7d6a92aa7b4e","rnd_rnhfk":"548a5288-c65d-43ac-be7c-fec662fc154a","rnd_awbfk":"bea8497f-b956-4a4a-9702-c5eddcf014c7"}"]
>>
>>(note I deleted a lot of the data so may not ave terminated the json properly)
>
>What code did you use to put the above *into* localStorage. Can you compare the output from the MVC Html.Raw() with the above object ?

I'm inching forward! (that's one thing that can't be converted to metric, it would sound very strange to say: "I'm centimetering forward").

I got it to work using this statement:
this.runSheetDetails = ko.observableArray(runsheetdetailsDataService.parse(localStorage[this.localKey]));
Now I just need to work out how to define my RunSheetDetails model properly in javascript.

I am defining it like this:
        var RunSheetDetails = function () {
            this.rnd_pk = ko.observable();
            this.rnd_rnhfk = ko.observable();
            this.rnd_awbfk = ko.observable();

            this.airWayBill = ko.observable();
            this.airWayBill.awb_pk = ko.observable();
            this.airWayBill.awb_number = ko.observable();
            this.airWayBill.rnd_awbfk = ko.observable();
            this.airWayBill.awb_pieces = ko.observable();
            this.airWayBill.awb_cusfk = ko.observable();

            this.airWayBill.customer = ko.observable();
            this.airWayBill.customer.cus_PK = ko.observable();
            this.airWayBill.customer.cus_lastname = ko.observable();
            this.airWayBill.customer.cus_firstname = ko.observable();
            this.airWayBill.customer.cus_company = ko.observable();
            this.airWayBill.customer.cus_addr1 = ko.observable();
            this.airWayBill.customer.cus_addr2 = ko.observable();
            this.airWayBill.customer.cus_number = ko.observable();

            this.DeliveryHistories = ko.observableArray();
            this.RunSheetHeader = ko.observable();
        };
but getting binding errors:

Uncaught ReferenceError: Unable to process binding "template: function (){return { name:'list-template',foreach:runSheetDetails} }"
Unable to process binding "text: function (){return airWayBill.awb_number }"
airWayBill is not defined

Can anyone spot a problem with what I've done?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform