zoukankan      html  css  js  c++  java
  • knockout not displaying images bound to the img element

    http://forums.asp.net/p/1982784/5681655.aspx?Re+knockout+not+displaying+images+bound+to+the+img+element

    The ImageDisplay.aspx and images are in the same folder.

    i would suggest you try the demo below:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImageDisplay.aspx.cs" Inherits="JqueryDemo_ImageDisplay" %>
    
    <!DOCTYPE html><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title></title><scriptsrc="../Scripts/jquery-2.1.0.js"type="text/javascript"></script><scriptsrc="../Scripts/knockout-3.1.0.js"type="text/javascript"></script><%--<script src="../Scripts/ImagesDisplay.js" type="text/javascript"></script>--%>
       
         <scripttype="text/javascript">/// <reference path="../Scripts/jquery-2.1.0.min.js" />/// <reference path="../Scripts/knockout-3.1.0.js" />functionImagesModelForEachRow(image1, image2, image3){var self =this;
                self.image1 = ko.observable(image1);
                self.image2 = ko.observable(image2);
                self.image3 = ko.observable(image3);}varImagesListModel=function(){var self =this;
                self.ImagesArray= ko.observableArray([]);
                self.GetImagesList=function(){
                    $.ajax({
    
                        type:"POST",
                        url:"ImageDisplay.aspx/getallImages",
                        data:{},
                        contentType:"application/json; charset=utf-8",
                        dataType:"json",
                        success: fnsuccesscallback,
                        error: fnerrorcallback
                    });function fnsuccesscallback(data){//$.each(data.d.ImagesList, function (idx, val) {//    debugger;                      //    self.ImagesArray.push(new ImagesModelForEachRow(val.Image1, val.Image2, val.Image3));//});                 
                        ko.utils.arrayForEach(data.d.ImagesList,function(val){
                            self.ImagesArray.push(newImagesModelForEachRow(val.Image1, val.Image2, val.Image3));});}function fnerrorcallback(result){
                        alert(result.statusText);}}}
    
            $(document).ready(function(){debugger;var v =newImagesListModel();          
                ko.applyBindings(v);});</script></head><body><formid="form1"runat="server"><div><divid="ImagesSCreen"><inputtype="button"data-bind="click: GetImagesList"value="Search"/><divdata-bind="foreach: ImagesArray"><divclass="item"><tableborder="2"><tbody><tr><td><imgwidth="800"height="533"data-bind="attr: { 'src': 'Images/' + image1() + '.png' }"/></td></tbody></table></div></div></div></div></form></body></html>

    Code Snippet:

    publicpartialclassJqueryDemo_ImageDisplay:System.Web.UI.Page{publicstaticstringImage1="image1";publicstaticstringImage2="image2";protectedvoidPage_Load(object sender,EventArgs e){}[WebMethod][ScriptMethod(ResponseFormat=ResponseFormat.Json)]publicstaticListOfImages getallImages(){Images images1 =newImages();
            images1.Image1="image1";
            images1.Image2="image1";
            images1.Image3="image1";ImagesImages2=newImages();Images2.Image1="image2";Images2.Image2="image2";Images2.Image3="image2";ListOfImages list =newListOfImages();
            list.ImagesList=newList<Images>();
            list.ImagesList.Add(images1);
            list.ImagesList.Add(Images2);return list;}}publicclassListOfImages{publicList<Images>ImagesList;}publicclassImages{publicstringImage1{set;get;}publicstringImage2{set;get;}publicstringImage3{set;get;}}

    Hope it helps you.

  • 相关阅读:
    阿里P8架构师谈:阿里双11秒杀系统如何设计?
    秒杀系统设计的知识点
    秒杀系统架构优化思路
    秒杀系统解决方案
    Entity Framework Code First (七)空间数据类型 Spatial Data Types
    Entity Framework Code First (六)存储过程
    Entity Framework Code First (五)Fluent API
    Entity Framework Code First (四)Fluent API
    Entity Framework Code First (三)Data Annotations
    Entity Framework Code First (二)Custom Conventions
  • 原文地址:https://www.cnblogs.com/happy-Chen/p/3683065.html
Copyright © 2011-2022 走看看