当前位置: 首页 > 工具软件 > jQuery Upvote > 使用案例 >

knockout得ajax,jquery - knockout ajax call data-BIND - Stack Overflow

南门新知
2023-12-01

I mostly agree with what Amit said (and given him my upvote), but if you want dynamic forms then you could also try Knockout's html binding (when you want to bind a few lines) and template binding (when you want to show entire sections of data).

I understand that you wish to combine Knockout, jQuery and Typescript but you must understand the point of each one, and make them compliment each other. Knockout and jQuery can both manipulate data on the UI. However, Knockout's core purpose is to keep the viewModel and View in sync, while jQuery started out as a library that made selection easier.

So my recommendation is use Knockout to modify the data on your UI, and jQuery to select and capture data.

Here's two examples of adding HTML using Knockout:

HTML binding:

Template binding:

Credits:

var viewModel = {

details: ko.observable(),

people: ko.observableArray()

};

ko.applyBindings(viewModel);

//simulate AJAX call with setTimeouts

setTimeout(function(){

viewModel.details("For further details, view the report here.");

},1000);

setTimeout(function(){

viewModel.people([

{ name: 'Franklin', credits: 250 },

{ name: 'Mario', credits: 5800 }

]);

},2000);

 类似资料: