Thuộc tính
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
4 là thuộc tính đặc biệt trong JustPy. Bạn không cần sử dụng nó, nhưng nếu bạn làm vậy, nó có thể làm cho mã của bạn ngắn gọn và dễ đọc hơn. Đó là một cách tao nhã và đơn giản để chia sẻ dữ liệu giữa các thành phần độc lập [nó được lấy cảm hứng từ chỉ thị import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
5 trong Vue. js và hoạt động theo cách tương tự]Hãy thử chạy chương trình sau và nhập vào trường nhập liệu trong trình duyệt
Minh họa trường nhập liệu¶
import justpy as jp
async def input_demo_model1[request]:
wp = jp.WebPage[data={ 'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model1]
Văn bản được nhập vào trường nhập liệu được phản ánh trong div trên trang. Kết nối giữa đầu vào và div được thực hiện bằng các thuộc tính
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
4 và import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
1. Lưu ý rằng khi chúng tôi tạo trang web, chúng tôi khởi tạo một thuộc tính import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
1. Thuộc tính import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
1 phải là từ điển Python. Trong trường hợp của chúng tôi, nó là một từ điển có một mục. Khóa là 'văn bản' và giá trị là 'Văn bản ban đầu'Khi chúng tôi tạo phần tử Đầu vào, chúng tôi thêm phần sau vào đối số từ khóa của nó.
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
4Điều này cho đối tượng Đầu vào biết rằng nó sẽ tự lập mô hình dựa trên giá trị bên dưới khóa 'văn bản' trong dữ liệu của
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
5. Đối với phần tử Đầu vào, điều này có nghĩa là khi được hiển thị, phần tử này sẽ lấy giá trị của nó từ import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
6 VÀ khi giá trị của nó bị thay đổi do một sự kiện đầu vào, nó sẽ đặt import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
6 thành giá trị mớiGhi chú
Điều quan trọng là phải hiểu rằng trong trường hợp Đầu vào,
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
4 có ảnh hưởng hai chiều. Nó nhận giá trị của nó từ thuộc tính dữ liệu thích hợp và khi một sự kiện đầu vào xảy ra, nó sẽ thay đổi thuộc tính dữ liệu thích hợpTrong trường hợp phần tử Div, mối quan hệ chỉ là một chiều. Thuộc tính văn bản của nó được hiển thị theo thuộc tính mô hình nhưng nó không thay đổi từ điển dữ liệu
Nếu một phần tử có một sự kiện đầu vào, thuộc tính mô hình hoạt động theo hai hướng, nếu không thì chỉ theo một hướng. Đối với hai phần tử định hướng, thuộc tính được thay đổi là giá trị trong khi đối với một phần tử định hướng, thuộc tính được thay đổi là văn bản
Điều này hữu ích như thế nào?
Bản trình diễn trường nhập liệu với ba div¶
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
Vì tất cả các phiên bản Div đều có cùng một mô hình nên chúng sẽ thay đổi khi chúng ta nhập. Không có thuộc tính mô hình, việc triển khai điều này sẽ dài dòng hơn
Bây giờ, hãy sao chép các Đầu vào. Hãy có năm Đầu vào thay vì một
Bản trình diễn trường nhập liệu với năm Đầu vào¶
import justpy as jp
async def input_demo_model3[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
for _ in range[5]:
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for _ in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model3]
Nhập vào bất kỳ một trong năm trường Đầu vào và xem điều gì sẽ xảy ra. Vì tất cả các yếu tố chia sẻ cùng một mô hình, tất cả chúng đều thay đổi song song. Chúng tôi không cần viết bất kỳ trình xử lý sự kiện nào
Hãy thực hiện một sửa đổi nhỏ cho chương trình và thêm nút đặt lại sẽ xóa tất cả các thành phần trên trang
Bản trình diễn trường nhập với nút đặt lại¶
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
0Khi nút được nhấp, lệnh sau trong
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
9 được thực thi. import justpy as jp
async def input_demo_model3[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
for _ in range[5]:
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for _ in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model3]
0Vì tất cả các Đầu vào và Div được mô hình hóa theo mục nhập từ điển này, nên tất cả chúng đều được đặt lại thành chuỗi trống khi nhấp vào nút
Ghi chú
Bất kỳ phần tử nào, chẳng hạn như Div, có thể có thuộc tính dữ liệu và được sử dụng trong thuộc tính mô hình, không chỉ một Trang web
Với các thuộc tính
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
4 và import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
1, bạn có thể dễ dàng truyền một thay đổi trong một phần tử sang các phần tử khácSử dụng nâng cao thuộc tính mô hình¶
Mẹo
Phần này của hướng dẫn sẽ sử dụng các thành phần tùy chỉnh. Tôi khuyên bạn nên bỏ qua phần này ban đầu và quay lại phần đó sau khi đã hoàn thành một số phần đầu tiên của phần Tạo thành phần tùy chỉnh của hướng dẫn
Chương trình sau đây là chương trình cơ sở chúng tôi sẽ mở rộng trên. Nó sử dụng
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
4 giống như các ví dụ trênsử dụng mô hình¶
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
4Khi bạn nhập văn bản vào
import justpy as jp
async def input_demo_model3[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
for _ in range[5]:
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for _ in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model3]
4, nó sẽ hiển thị ở bốn góc của cửa sổ. Ở mỗi góc có một Div chứa hai Div khác. Div thứ hai có thuộc tính import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
4 và văn bản trong đó thay đổi khi người dùng nhập vào import justpy as jp
async def input_demo_model3[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
for _ in range[5]:
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for _ in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model3]
4'`Nếu chúng ta muốn các góc hiển thị văn bản "Chưa nhập gì cả" khi
import justpy as jp
async def input_demo_model3[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
for _ in range[5]:
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for _ in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model3]
4 trống, cách tốt nhất để thực hiện điều này là tạo một thành phần mới với phương thức xử lý import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
4 phức tạp hơnChương trình sẽ trông như thế này
sử dụng mô hình phức tạp hơn¶
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
8Chúng tôi xác định một thành phần mới,
import justpy as jp
async def input_demo_model3[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
for _ in range[5]:
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for _ in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model3]
9 kế thừa từ import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
00 và giống hệt nhau ngoại trừ phương thức import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
01. Phương thức import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
01 tiêu chuẩn mà import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
00 đi kèm làimport justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
4Trong
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
01 của import justpy as jp
async def input_demo_model3[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
for _ in range[5]:
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for _ in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model3]
9, trước tiên chúng tôi kiểm tra xem giá trị để đặt thuộc tính import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
06 có phải là chuỗi rỗng hay không và nếu có, hãy gán cho nó chuỗi "Chưa nhập gì cả". Nó tạo ra chức năng mà chúng tôi đang tìm kiếmCác phương thức model_update phức tạp hơn¶
Chúng ta có thể đưa thêm chức năng vào hàm
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
01import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
9Chúng tôi thêm hai thuộc tính
import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
08 và import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
09 vào import justpy as jp
async def input_demo_model3[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
for _ in range[5]:
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for _ in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model3]
9. Đầu tiên, import justpy as jp
async def input_demo_model2[request]:
wp = jp.WebPage[data={'text': 'Initial text'}]
input_classes = "m-2 bg-gray-200 appearance-none border-2 border-gray-200 rounded xtw-64 py-2 px-4 text-gray-700 focus:outline-none focus:bg-white focus:border-purple-500"
jp.Input[a=wp, classes=input_classes, placeholder='Please type here', model=[wp, 'text']]
for i in range[3]:
jp.Div[model=[wp, 'text'], classes='m-2 p-2 h-32 text-xl border-2 overflow-auto', a=wp]
return wp
jp.justpy[input_demo_model2]
08 xác định số lần giá trị mô hình sẽ được lặp lại trong văn bản. Chúng tôi cung cấp cho mỗi góc một giá trị khác nhau