To display two-dimensional relationship data one by one, we can use the GIRD component. But in some situations, such as product displays and albums, we can use View components to display "matrix" data. The data source of View comes from DataModel object, which includes XMLDataModel and JSONDataModel. Although View supports JSON, if it is not used in a DataModel, the View subclass JSONView is more suitable because it provides more events and methods. Generally speaking, View is used for XML data sources; JSONView is used for JSON data sources.
How does View work?
Remember how to output a record before? Take an online store as an example; in the past, a product was output like this:
<div id="title">"; str+=rs("title")+""; str+="<img src="/static/imghwm/default1.png" data-src="+rs(" class="lazy" thumb_image alt="The seventh day of learning YUI.Ext--About View&JSONView_YUI.Ext" >"; str+="" Resposne.Write(str); ..... %> <p>Obviously, our ultimate goal is to output HTML and serve the browser rendering (Render). The working principle of View is the same, except that the things previously done by Sever are moved to Cilent, relying on View to handle them (essentially the template of Domhelper), and letting the browser finally render the output. </p> <p><strong>Need your help: Domhelper</strong></p> <p>As mentioned above, View cannot work without DomHelpr. DomHelpr provides "Template" here and compiles it. See the code below: </p> <pre class="brush:php;toolbar:false"><br>//新建一个Template对象 var tpl = <span class="style3">new YAHOO.ext.Template</span>(<br> '<div class="entry">' + <br> '<a class="entry-title" href="%7Blink%7D">{title}</a>' +<br> '<h4 id="date-by-author-comments-Comments">{date} by {author} | {comments} Comments</h4>{description}' +<br> '</div><hr>'<br>); tpl.compile(); //compile()的方法,可带来DOM性能的增益 var moreView = new YAHOO.ext.JsonView('entry-list', tpl, { jsonRoot: 'posts' }); //又或者隐式创建Template对象 var view = new YAHOO.ext.View('my-element', <span class="style1">'<div id="{0}">{2} - {1}</div>'</span>, // auto create template dataModel, { singleSelect: true, selectedClass: 'ydataview-selected' });
Loading data
The way VIEW loads data is different from that of JSONView: VIEW uses DataModel's load(), and JSONView uses UpateManager's load(). Let’s focus on the load() method of JSONView:
view.load({ url: 'your-url.php',<br> params: {param1: 'foo', param2: 'bar'}, // 可以是URL encoded字符<br> callback: yourFunction,<br> scope: yourObject, //(optional scope) <br> discardUrl: false, <br> nocache: false,<br> text: 'Loading...',//loading之提示文字<br> timeout: 30,//超时<br> scripts: false<br> });
Only the url parameter is not optional, others such as nocache, text and scripts are optional. text and scripts are parameters associated with the UpdateManger instance
- params : String/Object
(optional) The parameters to pass as either a url encoded string "param1=1¶m2=2" or an object {param1: 1, param2: 2}
- callback : Function
(optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
- discardUrl : Boolean
(optional) By default when you execute an update the defaultUrl is changed to the last used url. If true, it will not store the url.
JSONView usage tips
a. There is a gird and a JSONView. How do they call a data source at the same time?
1. Change the jsonData attribute; 2.Call refresh(); See http://www.yui-ext.com/forum/viewtopic.php?t=1968
b. Paging
There seems to be no good solution for paging yet. JACK only provides the following ideas:
JsonView extends View. View supports using a JSONDataModel. It won't render a paging toolbar for you, but it will loadPage() and standard DataModel functionality. The view will automatically update when you load new data. If you want named template parameters (like JsonView), you will need to remap the indexes (DataModel style) to named parameters. See the YAHOO.ext.View docs for more info on that.
http://www.yui-ext.com/forum/viewtopic.php?t=2340
c. How to get the entire DataModel instead of fields in JSONView? Every time I use alert(mainView.jsonData); the result is "undefined"
If you are getting the DataModel, you should use the View object. The reason for undefined is that load() is asynchronous, and you must wait for the data to be loaded first. Such as:
mainView.el.getUpdateManager().on('update', function(){ alert(mainView.jsonData); });
See http://www.yui-ext.com/forum/viewtopic.php?t=1209
d. Study examples. The exampleImage Chooser itself is a good learning example
JSON Format
You might think that the service outputs JSON like this:
{"user": {"username": "Bob", "birthday": "1976-11-08", "join_date": "2006-08-01", "last_login": "2006-12-03"}}
is correct. But no, it cannot be processed. The correct format should be:
{"user": <strong style="COLOR: red">[</strong>{"username": "Bob", "birthday": "1976-11-08", "join_date": "2006-08-01", "last_login": "2006-12-03"}<strong style="COLOR: red">]</strong>}
Note that the array type is declared within the square brackets, and the View rendering method is actually consistent with the DataModel
Finally, provide a UML diagram of Veiw


Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

Bring matrix movie effects to your page! This is a cool jQuery plugin based on the famous movie "The Matrix". The plugin simulates the classic green character effects in the movie, and just select a picture and the plugin will convert it into a matrix-style picture filled with numeric characters. Come and try it, it's very interesting! How it works The plugin loads the image onto the canvas and reads the pixel and color values: data = ctx.getImageData(x, y, settings.grainSize, settings.grainSize).data The plugin cleverly reads the rectangular area of the picture and uses jQuery to calculate the average color of each area. Then, use

This article will guide you to create a simple picture carousel using the jQuery library. We will use the bxSlider library, which is built on jQuery and provides many configuration options to set up the carousel. Nowadays, picture carousel has become a must-have feature on the website - one picture is better than a thousand words! After deciding to use the picture carousel, the next question is how to create it. First, you need to collect high-quality, high-resolution pictures. Next, you need to create a picture carousel using HTML and some JavaScript code. There are many libraries on the web that can help you create carousels in different ways. We will use the open source bxSlider library. The bxSlider library supports responsive design, so the carousel built with this library can be adapted to any

Data sets are extremely essential in building API models and various business processes. This is why importing and exporting CSV is an often-needed functionality.In this tutorial, you will learn how to download and import a CSV file within an Angular


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)