MVVM schema ~knockoutjs series for Ajax passing KO array objects

Source: Internet
Author: User

Back to Catalog

Something to say.

This is a very interesting topic, in Ko, there are objects and arrays of objects two, but both of these objects are a function of external performance, if you want to get his value, you need to make a functional call, such as Ko_a (), its result is a specific value or array or function, and ko_ A represents a Ko object.

Today, I would like to talk about how to pass objects and arrays to the background in the Ajax method, in general, we pass strings and numbers for the background, and if we want to pass the object, we need to use the $.param method, the following specific code to say.

Something to do.

Generally after the code ideal is like this

    Public Jsonresult generatororder (int[] idarr)//Some shopping cart record ID that needs to be generated order        {            //  Todo:generator Order            return  Json (Idarr);        }

And such a background interface, our front-end Ajax parameters need to do a $.param processing, as follows

$.ajax ({type:"Post", URL:"/order/generatororder", Data: $.param (self. Selcart (),true),//It is not possible to use the array directly as a $.param parameter .DataType:"JSON", Success:function (data) {Boxy.alert ("To Paypage of products :"+json.stringify (data)); }                });

In fact, the above code run the result is wrong, because the $.param method only supports the object, does not support the direct array, and the array if it can be supported in the object, it is also interesting, so the above code we need to modify

$.ajax ({type:"Post", URL:"/order/generatororder", Data: $.param ({idarr:self. Selcart ()},true),//! Note to pass the second argumentDataType:"JSON", Success:function (data) {Boxy.alert ("To Paypage of products :"+json.stringify (data)); }                });

The following run results are what we want to see

Back to Catalog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.