如何使用复选框和图标获取jQuery移动列表视图

时间:2012-06-12 20:34:36

标签: jquery css mobile jquery-mobile

我尝试在jQuery mobile listview附带的图像中获得布局。我目前正在使用星形图像上的.ui-li-icon类,但即使我用自己的css属性覆盖定位,我也不会将它向右移动。

我当然可以强迫星星在右边的位置:绝对;但这会在不同的平台上以及横向与纵向模式之间产生问题。

在jQuery mobile中获得如下布局的最佳方法是什么?

图片:http://a4.mzstatic.com/us/r1000/095/Purple/ff/1d/33/mzl.ecpvufek.320x480-75.jpg

2 个答案:

答案 0 :(得分:2)

我重新考虑了我的旧答案并重新解决了问题,特别是为了适应mvc 4框架,但客户端却完全相同。
所以让我们开始:
如果你只是想要html,你可以在这里得到它 此链接指向3部分复选框列表,复选框,项目链接和信息弹出窗口:

Here is the link to jsfiddle for working listview with checkbox AND icon

iv最后添加了2个部分的列表框和单个部分,如有任何问题请告诉我。

现在对于控制器,你需要做的就是

[Authorize]
public ActionResult Items(string act, 
    string tab, string search_by, string search, string sort, string sortdir, int? page, int? resultsPerPage,
    List<int> selected, int? projectId, string username)
{
    if (act == "AddItemsToUser")
    {
        string response;
        if (selected != null)
        {
            response = "Project Items Added:";
            foreach (var item in selected)
            {
                try
                {
                    if (username != null)
                        if (UserItemRecordModel.InsertUserItem(username, item, null, null, 0, null, null))
                            response += item + " - inserted, ";
                }
                catch (Exception ex)
                {
                    response += item + " - " + ex.Message + ", ";
                }
            }
            response.TrimEnd(' ', ',');
        }
        else
        {
            response = "No Items Were Selected!";
        }
        return Json(response, JsonRequestBehavior.AllowGet);
    }
    else if (act == "AddItemsToProject")
    {
        string response;
        if (selected != null)
        {
            response = "Project Items Added:";
            foreach (var item in selected)
            {
                try
                {
                    if (projectId != null)
                        if (ProjectItemRecordModel.InsertProjectItem(projectId.ToString(), item, null, null, 0, null, null))
                            response += item + " - inserted, ";
                }
                catch (Exception ex)
                {
                    response += item + " - " + ex.Message + ", ";
                }
            }
            response.TrimEnd(' ', ',');
        }
        else
        {
            response = "No Items Were Selected!";
        }
        return Json(response, JsonRequestBehavior.AllowGet);
    }
    else if (act == "RemoveItemsFromUser")
    {
        string response;
        if (selected != null)
        {
            response = "Project Items Removed:";
            foreach (var item in selected)
            {
                try
                {
                    if (UserItemRecordModel.DeleteUserItem(username, item))
                        response += item + " - deleted, ";
                }
                catch (Exception ex)
                {
                    response += item + " - " + ex.Message + ", ";
                }
            }
            response.TrimEnd(' ', ',');
        }
        else
        {
            response = "No Items Were Selected!";
        }
        return Json(response, JsonRequestBehavior.AllowGet);
    }
    else if (act == "RemoveItemsFromProject")
    {
        string response;
        if (selected != null)
        {
            response = "Project Items Removed:";
            foreach (var item in selected)
            {
                if (ProjectItemRecordModel.DeleteProjectItem(projectId.ToString(), item))
                    response += item + " - deleted, ";
            }
            response.TrimEnd(' ', ',');
        }
        else
        {
            response = "No Items Were Selected!";
        }
        return Json(response, JsonRequestBehavior.AllowGet);
    }

    List<ItemRecordModel> items = ItemRecordModel.GetSensors(search_by, search, sort, sortdir);
    return View("Items", new AdminRecordsViewModel() { Records = items });
}

这是我的老答案:
我解决了你需要改变一些东西的问题,但你可以用复选框完成一个可搜索的列表视图:

jsfiddle例子:


碱性的: basic jsfiddle version

更好的版本: nicer version

jquery mobile listview with checkbox and icon or image

答案 1 :(得分:0)